我想在屏幕上有一个“徽章”,当条件满足时,它会从正常大小反弹到更大,然后反复恢复正常,直到不再满足条件。不过,我似乎无法让徽章停止“弹跳”。一旦开始,势不可挡。
我尝试过的: 我尝试过使用一些动画,但它们可以分为使用“repeatForever”来达到预期效果的动画和不使用的动画。例如:
Animation.default.repeatForever(autoreverses: true)
和
Animation.spring(response: 1, dampingFraction: 0, blendDuration: 1)(将阻尼设置为 0 使其永远消失)
然后用 .animation(nil) 把它换掉。似乎不起作用。有没有人有任何想法?非常感谢您提前!这是重现它的代码:
struct theProblem: View {
@State var active: Bool = false
var body: some View {
Circle()
.scaleEffect( active ? 1.08: 1)
.animation( active ? Animation.default.repeatForever(autoreverses: true): nil )
.frame(width: 100, height: 100)
.onTapGesture {
self.active = !self.active
}
}
}
Run Code Online (Sandbox Code Playgroud)