You cannot animate the number of lines, you must animate the size and set the number of lines to 0 from the very beginning.
I am not adding height calculation code since it hides the real animation here.
self.locationDescription = [[UILabel alloc] init]; self.locationDescription.numberOfLines = 0; [locationDescription setTranslatesAutoresizingMaskIntoConstraints:NO]; // Say, it starts with 50. In your real code, height should be calculated // to fit the size you want, rounded to lines NSDictionary *viewsDict = @{@"locationDescription": self.locationDescription}; [self.locationDescription addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"V:[locationDescription(50)]" options:0 metrics:nil views:viewsDict];
Then in action do
- (void)buttonPressed:(UIButton *)sender { NSLog(@"Pressed"); // Assuming there is only one constraint. If not, assign it to another property // I put 500, but, again, real size rounded to line height should be here self.locationDescription.constraints[0].constant = 500; [UIView animateWithDuration:1 animations:^{ // Layouting superview, as its frame can be updated because of a new size [self.locationDescription.superview layoutIfNeeded]; }]; }
In addition, you must assign a locationDescription to the property and access it with self. in front.
coverback
source share