I migrated my code from Swift 1.2 to Swift 2.0
In Swift 1.2/ iOS8 , the animation just works. But in iOS 9, it does not animate it, the Label changes the position immediately as if the layoutIfNeeded
was never called.
Here is how I animate my UILabel an UIButton. (I am using Autolayout, that's why I use layoutIfNeeded)
USING UILABEL (DOES NOT WORK)
titleLabelTopConstraint.constant = 88;
UIView.animateWithDuration(0.8, delay: 0.38, usingSpringWithDamping: 0.54, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.titleLabel.layoutIfNeeded();
}, completion: nil);
USING UIBUTTON (IT WORKS)
buttonTopConstraint.constant = 88;
UIView.animateWithDuration(0.8, delay: 0.38, usingSpringWithDamping: 0.54, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
self.button.layoutIfNeeded();
}, completion: nil);
However if I do the same on an UIButton, it works!.
Any thoughts? Why UILabel is not animatable?
Try adding:
self.titleLabel.setNeedsLayout();
before the animation block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With