Adding Constraints
You now have two arrays of NSLayoutConstraint objects. However, these constraints will have no effect on the layout until you explicitly add them using the UIView method
- (void)addConstraints:(NSArray *)constraints
Which view should receive the addConstraints: message? Usually, the closest common ancestor of the views that are affected by the constraint. Here is a list of rules you can follow to determine which view you should add constraints to:
-
If a constraint affects two views that have the same superview (such as the constraint labeled “A” in Figure 16.1), then the constraint should be added to their superview.
-
If a constraint affects just one view (the constraint labeled “B”), then the constraint ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access