Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 Breaks Animations of UILabel

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?

like image 778
JayVDiyk Avatar asked Sep 08 '15 16:09

JayVDiyk


1 Answers

Try adding:

self.titleLabel.setNeedsLayout();

before the animation block.

like image 52
john_ryan Avatar answered Nov 16 '22 01:11

john_ryan