Before Auto Layout, iOS applications used another system for managing layout: autoresizing masks. Each view had an autoresizing mask that constrained the relationship between a view and its superview, but this mask could not affect relationships between sibling views.
By default, views create and add constraints based on their autoresizing mask. However, these translated constraints often conflict with your explicit constraints in your layout, which results an unsatisfiable constraints problem.
To see this happen, comment out the line in viewDidLoad that turns off the translation of autoresizing masks.
// The contentMode of the image view in the XIB was Aspect Fit: iv.contentMode = UIViewContentModeScaleAspectFit;// Turn off old-school layout handling iv.translatesAutoresizingMaskIntoConstraints = NO;// The image view was a subview of the view [self.view addSubview:iv];
Now the image view has a resizing mask that will be translated into a constraint. Build and run the application and navigate to the detail interface. You will not like what you see. The console will report the problem and its solution.
Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x914a2e0 H:[UILabel:0x914a1e0(42)]>", "<NSLayoutConstraint:0x9153ee0 H:|-(20)-[UILabel:0x9149f00] (Names: '|':UIControl:0x91496e0 )>", "<NSLayoutConstraint:0x9153fa0 UILabel:0x9149970.leading == UILabel:0x9149f00.leading>", "<NSLayoutConstraint:0x91540c0 UILabel:0x914a1e0.leading == UILabel:0x9149970.leading>", "<NSLayoutConstraint:0x9154420 H:[UITextField:0x914fe20]-(20)-| (Names: '|':UIControl:0x91496e0 )>", "<NSLayoutConstraint:0x9154450 H:[UILabel:0x914a1e0]-(12)-[UITextField:0x914fe20]>", "<NSLayoutConstraint:0x912f5a0 H:|-(NSSpace(20))-[UIImageView:0x91524d0] (Names: '|':UIControl:0x91496e0 )>", "<NSLayoutConstraint:0x91452a0 H:[UIImageView:0x91524d0]-(NSSpace(20))-| (Names: '|':UIControl:0x91496e0 )>", "<NSAutoresizingMaskLayoutConstraint:0x905f130 h=--& v=--& UIImageView:0x91524d0.midX ==>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x914a2e0 H:[UILabel:0x914a1e0(42)]>
Let’s go over this output. Auto Layout is reporting that it is “Unable to simultaneously satisfy constraints.” This happens when a view hierarchy has constraints that conflict.
Then, the console spits out some handy tips and a list of all constraints that are involved. Each constraint’s description is shown in the console. Let’s look at the format of one of these constraints more closely.
<NSLayoutConstraint:0x9153fa0 UILabel:0x9149970.leading == UILabel:0x9149f00.leading>
This description indicates that the constraint located at memory address 0x9153fa0 is setting the leading edge of the UILabel (at 0x9149970) equal to the leading edge of the UILabel (at 0x9149f00).
Four of these constraints are instances of NSLayoutConstraint. The fifth, however, is an instance of NSAutoresizingMaskLayoutConstraint. This constraint is the product of the translation of the image view’s autoresizing mask.
Finally, it tells you how it is going to solve the problem by listing the conflicting constraint that it will ignore. Unfortunately, it chooses poorly and ignores one of your explicit instances of NSLayoutConstraint instead of the NSAutoresizingMaskLayoutConstraint. This is why your interface looks like it does.
The note before the constraints are listed is very helpful: the NSAutoresizingMaskLayoutConstraint needs to be removed. Better yet, you can prevent this constraint from being added in the first place by explicitly disabling translation in viewDidLoad:
// The contentMode of the image view in the XIB was Aspect Fit: iv.contentMode = UIViewContentModeScaleAspectFit; // Do not produce a translated constraint for this view iv.translatesAutoresizingMaskIntoConstraints = NO; // The image view was a subview of the view [self.view addSubview:iv];