我在 SwiftUI 中有一个图像,我希望它永远“脉动”(每秒左右来来去去)。
我尝试了很多方法,但似乎无法达到我想要的效果。我尝试过的事情之一是下面的代码(它似乎什么也没做!:))。
Image(systemName: "dot.radiowaves.left.and.right" )
.foregroundColor(.blue)
.transition(.opacity)
.animation(Animation.easeInOut(duration: 1)
.repeatForever(autoreverses: true))
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
这是一种方法。使用 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 }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2151 次 |
| 最近记录: |