condor304
condor304

Reputation: 209

Error: Unable to simultaneously satisfy constraints

I get this error:

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:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names:    '|':UIView:0x1600a980 )>",
 "<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0]   (Names: '|':UIView:0x1600a980 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>",
"<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names: '|':UIView:0x1600a980    )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in 
<UIKit/UIView.h> may also be helpful.

the view that generates this error has 4 constrains for left/right/top/bottom and I can not delete any of them.

I have tried:

[View setTranslatesAutoresizingMaskIntoConstraints:NO];

with no result.

do you have any idea how to fix this?

Thank you!

Upvotes: 1

Views: 2486

Answers (2)

Sulthan
Sulthan

Reputation: 130072

The problem is in the vertical layout.

<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>

Autoresizing mask for a window. Fixed margins and size. You can't change this.

<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>

Autoresing mask (fixed margins, resizable content). Probably the view of your controller. The height is 480 (set to be equal to the size of the window). Nothing to fix here.

<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names:    '|':UIView:0x1600a980 )>
<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0]   (Names: '|':UIView:0x1600a980 )>

You can notice that both constraints are doing something with the same view ([UIView:0x102021d0]) and have the same second view as a parameter (UIView:0x1600a980). The second view is our controller's view.

The two constraints define distances from edges of the second view. The first defines bottom (0). The second one defines top (494). If the superview's size is 480, that means [UIView:0x102021d0] would have height equal to -14 which triggers that exception.

How to fix it? Well, change the 494 constraint to the correct value. It's possible you don't even want the "top" constraint, maybe you want a fixed height instead.

How did the problem arise? You probably created your constraints for iPhone 5 and then you tried to run the app with iPhone 4. If you change the simulated size in your xib to iPhone 4, you should see the problem immediately.

Upvotes: 4

Maarten
Maarten

Reputation: 1873

There are still views that have translatesAutoresizingMaskIntoConstraints set to YES, apparently, otherwise you wouldn't be getting that message. It's probably the superview of the view that's giving you problems. Make sure that it also doesn't translate its autoresizing masks to constraints.

Upvotes: 0

Related Questions