【问题标题】:SwiftUI - how to pulsate image opacity?SwiftUI - 如何脉动图像不透明度?
【发布时间】:2020-05-13 15:06:35
【问题描述】:

我在 SwiftUI 中有一个图像,我想永远“脉动”(每秒钟左右来来去去)。

我尝试了很多方法,但似乎无法获得我想要的效果。我尝试过的其中一件事是下面的代码(似乎什么也没做!:))。

Image(systemName: "dot.radiowaves.left.and.right" )
.foregroundColor(.blue)
.transition(.opacity)
.animation(Animation.easeInOut(duration: 1)
    .repeatForever(autoreverses: true))

有什么想法吗?

【问题讨论】:

    标签: animation swiftui


    【解决方案1】:

    这是一种方法。使用 Xcode 11.4 / iOS 13.4 测试

    struct DemoImagePulsate: View {
        @State private var value = 1.0
        var body: some View {
            Image(systemName: "dot.radiowaves.left.and.right" )
                .foregroundColor(.blue)
                .opacity(value)
                .animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true))
            .onAppear { self.value = 0.3 }
        }
    }
    

    【讨论】:

    • 你能解释一下这里发生了什么吗?我不知道value 的更改位置...
    猜你喜欢
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 2016-12-02
    • 2012-02-22
    相关资源
    最近更新 更多