问题
I have an animation thats running fine in iOS 8.1 but in iOS 7.1 the button just appears where it is supposed to be without animation.
The button has leading, trailing and bottom constraints of 0, and height constraint of 80. The constraints are setup in the storyboard.
In the viewWillAppear method I change the bottom constraint to -80 so it isn't seen in the beginning.
When the user presses a button, the button should animate up, I run this method:
func animateCtaUp() {
self.ctaView.layoutIfNeeded()
UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
self.ctaViewBottomConstraint.constant = 0
self.ctaView.layoutIfNeeded()
}, completion: { finished in
})
}
回答1:
Basically there were 2 bugs.
The first one was: I had a view without layout constraints. When I added them one of the animations started running.
The second bug was: I was calling
self.ctaView.layoutIfNeeded()
Instead I should be calling
self.view.layoutIfNeeded
来源:https://stackoverflow.com/questions/27907570/swift-animatewithduration-not-working-in-ios-7