AppsDev
AppsDev

Reputation: 12499

Identifying constraints when getting "Unable to simultaneously satisfy constraints"

I get this log when rotating certain view to landscape:

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:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>",
"<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>",
"<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>",
"<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>"

)

Will attempt to recover by breaking constraint

<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.

And I don't understand anything. I added the symbolic UIViewAlertForUnsatisfiableConstraints breakpoint but memory addresses tell me nothing... How can I find in a more understable way the constraints this log is talking about?

Thanks in advance

Upvotes: 1

Views: 166

Answers (2)

Ken Thomases
Ken Thomases

Reputation: 90551

You can re-order the constraints so that views appear in a consistent order. So, the original:

<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>
<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>

becomes:

<NSLayoutConstraint:0x17009b580 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(82)-[UILabel:0x14c51ed20'Welcome to...']>
<NSLayoutConstraint:0x17009b3f0 V:[UILabel:0x14c51ed20'Welcome to...'(>=54)]>
<NSLayoutConstraint:0x17009b2b0 V:[UILabel:0x14c51ed20'Welcome to...']-(30)-[UIView:0x14c51e7e0]>

<NSLayoutConstraint:0x170280230 V:[MyApp.LogoHeaderView:0x14c51f3e0]-(0)-[UIView:0x14c51e7e0]>

So, you have, vertically, an instance of MyApp.LogoHeaderView with 82 points between it and a label reading "Welcome to...". That label is greater than or equal to 54 points tall. Then there are 30 points between it and a UIView. Meanwhile, you've set a constraint saying there should be no distance between that UIView and your MyApp.LogoHeaderView. The conflict is that some of the constraints require that there's at least 82 + 54 + 30 == 166 points between the MyApp.LogoHeaderView and the UIView while another constraint says there's 0 points between them.

Do you really have multiple places in your UI where there's a MyApp.LogoHeaderView and a label reading "Welcome to..."?

Upvotes: 0

Thallius
Thallius

Reputation: 2619

When you define the constraints in IB, I think there is no way to get more information. But What is the problem? You know the label and the view. Now you can take a look at your constraints for this view. In worse case remove all objects and add them one by one and run the app everytime you added the next item. Then you will find the error.

Upvotes: 0

Related Questions