S.J S.J - 1 year ago 119
Objective-C Question

Autolayout not animating in iOS 10 but working fine in iOS 9

- (IBAction)btnA:(id)sender {
if(self.height.constant == 300) {
self.height.constant = 50;
} else {
self.height.constant = 300;

[self.subView1 setNeedsUpdateConstraints];

[UIView animateWithDuration:1.0 animations:^{
[self.subView1 layoutIfNeeded];

I am using this code but on
its not animating its just jump increasing and decreasing mySubview1 height. Why?

Same code is working fine in

Answer Source

For iOS10 its the view's superview which you have to force layout.

//Force apply all constraints prior to the change in constant.
[self.view.superview layoutIfNeeded];

//Update constant
self.height.constant = 0;

[UIView animateWithDuration:1.0 animations:^{
    [self.view.superview layoutIfNeeded];

I believe this behaviour is caused by the change in Xcode8 - iOS10 layout