S.J S.J - 2 months ago 36
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
iOS10
its not animating its just jump increasing and decreasing mySubview1 height. Why?

Same code is working fine in
iOS9

Answer

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

References:

http://stackoverflow.com/a/39501882

http://stackoverflow.com/a/39548367/1045672

Comments