iOS: How does one animate to new autolayout constraint (height) iOS: How does one animate to new autolayout constraint (height) ios ios

iOS: How does one animate to new autolayout constraint (height)


After updating your constraint:

[UIView animateWithDuration:0.5 animations:^{[self.view layoutIfNeeded];}];

Replace self.view with a reference to the containing view.


This works for me (Both iOS7 and iOS8+). Click on the auto layout constraint you would like to adjust (in interface builder e.g top constraint). Next make this an IBOutlet;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;

Animate upwards;

    self.topConstraint.constant = -100;        [self.viewToAnimate setNeedsUpdateConstraints];     [UIView animateWithDuration:1.5 animations:^{        [self.viewToAnimate layoutIfNeeded];     }];

Animate back to original place

    self.topConstraint.constant = 0;        [self.viewToAnimate setNeedsUpdateConstraints];      [UIView animateWithDuration:1.5 animations:^{        [self.viewToAnimate layoutIfNeeded];    }];


There is a very good tutorial from apple itself that explain how to use animation with autolayout.Follow this link and then find the video named "Auto layout by example"It gives some interesting stuff about autolayout and the last part is about how to use animation.