Reputation: 3408
I was digging into iOS 6.0 new feature Auto Layout, I created a sample app which has one view controller and two UIView as subview.I provided following constraints:
When I execute the following app in Landscape mode and rotate it to portrait, it works fine but when I execute it in portrait mode and rotate to Landscape it throws exception:
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)
(
"<NSAutoresizingMaskLayoutConstraint:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d8c0 V:|-(20)-[UIView:0x716d540] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>
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.
2012-10-22 11:37:37.297 AutoLayoutSample[679:c07] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d840 V:|-(20)-[UIView:0x716d230] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>
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.
My question is why it is throwing exception when I execute in portrait mode and rotate to landscape?And why constrains are behaving differently?
Upvotes: 2
Views: 2476
Reputation: 1164
The system is automatically turning the default resizing masks into constraints, which then conflict with yours. Add calls to [view setTranslatesAutoresizingMaskIntoConstraints:NO]
for both of your subviews and the NSAutoresizingMaskLayoutConstraints will go away, along with the exception.
Upvotes: 3