我在我的应用程序中使用Spring 库来制作动画效果。
就我而言,我必须为动作按钮设置动画,所以我添加了以下代码块。
override func viewDidLoad() {
super.viewDidLoad()
setOptions()
}
func setOptions() {
testButton.animation = Spring.AnimationPreset.Shake.rawValue
testButton.curve = Spring.AnimationCurve.EaseIn.rawValue
}
@IBAction func testButtonPressed(_ sender: Any) {
animateView()
}
在上面的代码流中,动画动作只发生一次。
但是,如果我按如下方式更新“testButtonPressed”方法,
@IBAction func testButtonPressed(_ sender: Any) {
setOptions()
animateView()
}
每次按下 testButton 时都会出现动画。
为什么我每次都必须更新动画属性?只更新一次属性还不够吗?