我正在尝试用约束为我的取消按钮设置动画,并且动画无法正常工作 [英] i am trying to animate my unbutton with a constraint and the animation is not working
本文介绍了我正在尝试用约束为我的取消按钮设置动画,并且动画无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我为什么这不是动画吗?我觉得代码很完美,但是动画功能不起作用。按钮立即从一侧跳到另一侧,但是就像我说的那样,它没有动画...
Can some one please tell me why this is not animating? I feel that the code is all perfect but the animate function is not working. The button is jumping instantly from side to side but like i said it isn't animating...
func moveResetButton( constraint : NSLayoutConstraint, isOffScreen : Bool) {
if isOffScreen {
//animate the button onto the screen
UIView.animate(withDuration: 3.0, delay: 0.0, options: .curveLinear, animations: {
constraint.constant += 120
}, completion: nil)
} else {
//animate the button off of the screen
UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveLinear, animations: {
constraint.constant -= 120
}, completion: nil)
}
}
推荐答案
我知道了。只需在约束更改下将 self.view.layoutIfNeeded()
添加到代码中即可。工作顺利。
i figured it out. just need to add self.view.layoutIfNeeded()
to the code under the constraint change. worked smoothly.
这篇关于我正在尝试用约束为我的取消按钮设置动画,并且动画无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文