我在 SwiftUI 中有一个图像,我希望它永远“脉动”(每秒左右来来去去)。
我尝试了很多方法,但似乎无法达到我想要的效果。我尝试过的事情之一是下面的代码(它似乎什么也没做!:))。
Image(systemName: "dot.radiowaves.left.and.right" )
.foregroundColor(.blue)
.transition(.opacity)
.animation(Animation.easeInOut(duration: 1)
.repeatForever(autoreverses: true))
有任何想法吗?
这是一种方法。使用 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 }
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)