0

I have a view that automatically adjusts it's height based on number of lines in a UILabel within the view. There is another view which height is pinned to be equal to the view with the label.

I would like to animate the height change caused by setting long text to the label, thus changing the number of lines and causing autolayout constraints to recalculate height. This new height will change the height of the second view too. How can I animate autolayout changes that happen as a side effect of property assignment?

I tried this, but it did not work:

[UIView animateWithDuration:0.3 animations:^{

    //I want the side effect of this assignment to be animated
    self.viewWithLabel.title = @"This long title will change the view height and cause layout change";

}]; 
Alex Stone
  • 46,408
  • 55
  • 231
  • 407

1 Answers1

0

See the documentation

Try:

- (void)viewDidAppear:(BOOL)animated {
    [self.view layoutIfNeeded];
    [UIView animateWithDuration:1.0 animations:^{

        self.viewWithLabel.title = @"This long title will change the view height and cause layout change";

        [self.view layoutIfNeeded];
    }];
}

I think you want yourTextLabel.clipToBounds = YES also.
If you want more advanced effect, see this question.

Community
  • 1
  • 1
rintaro
  • 51,423
  • 14
  • 131
  • 139