有人可以告诉我为什么这不是动画?我觉得代码是完美的,但是animate功能不起作用。按钮瞬间从一侧跳到另一侧,但就像我说它不是动画......
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)
}
}
答案 0 :(得分:0)
self.view.layoutIfNeeded()
。工作顺利。