问题
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)
}
}
回答1:
i figured it out. just need to add self.view.layoutIfNeeded()
to the code under the constraint change. worked smoothly.
来源:https://stackoverflow.com/questions/43647445/i-am-trying-to-animate-my-unbutton-with-a-constraint-and-the-animation-is-not-wo