Autolayout problems with iOS8 with code that works fine on iOS7

@robmayoff has a great answer for this: https://stackoverflow.com/a/26066992/1424669

Essentially, in iOS8 you can no longer call setNeedsUpdateConstraints and setNeedsLayout on a view and expect the constraints of subviews to update.

You must call these methods on the view whose constraint is changing. This is backwards compatible to iOS7.

EXAMPLE:

Suppose you have a ViewController with root view self.view and a subview called containerView. containerView has a NSLayoutConstraint attached to it that you want to change (in this case, top space).

In iOS7 you could update all constraints in a VC by requesting a new layout for the root view:

self.containerView_TopSpace.constant = 0;
[self.view setNeedsUpdateConstraints];
[self.view setNeedsLayout];

In iOS8 you need to request layouts on the containerView:

self.containerView_TopSpace.constant = 0;
[self.containerView setNeedsUpdateConstraints];
[self.containerView setNeedsLayout];

Leave a Comment