我想制作带有偏移的抖动效果,希望在 30.0 和 -30.0 之间的起始和抖动处具有零偏移,覆盖此偏移:-30.0, 0.0, 30.0
但在编码中我不能有这 3 个选项,而我有 2 个选项,我的目标是从 0.0 开始,到 30.0,然后到 -30.0,最后到 0.0
struct ContentView: View {
@State private var start: Bool = false
var body: some View {
Image(systemName: "exclamationmark.triangle")
.font(Font.system(size: 50))
.offset(x: start ? 30.0 : -30.0)
.padding()
.animation(Animation.spring(response: 0.2, dampingFraction: 0.2, blendDuration: 0.2), value: start)
Button("Shake") {
start.toggle()
}
}
}
Run Code Online (Sandbox Code Playgroud)