UILabel animated width reduction not showing

I am trying to reduce the width of a UILabel inside an animation, but the width changes instantly without animation! If I increase the width, everything will be fine, and you can see the animation.

Here is my code:

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveLinear animations:^ (void){ CGRect theNewFrame = self.titleLabel.frame; theNewFrame.size.width -= 50.0; self.titleLabel.frame = theNewFrame; } completion:^(BOOL finished){}]; 

So if I change

 theNewFrame.size.width -= 50.0; 

to

 theNewFrame.size.width += 50.0; 

You can watch the mark increase. But reducing the width will not work!

I have no explanation for this behavior. This is mistake?

Thank you for your responses!

+4
source share
1 answer

Try setting the contentMode label to UIViewContentModeCenter before starting the animation.

 self.titleLabel.contentMode = UIViewContentModeCenter; 
+1
source

Source: https://habr.com/ru/post/1394588/


All Articles