Reputation: 23
I test very simple layout with autolayout use storyboard only(no code any where)
i dropped the Button object wAny, hAny and then switch size class to wCompact, hAny
and add Constraint 'Center Horizontally in Container' & 'Top Space to Top layout guide'.
next i switch size class to wAny, hCompact and add constraint 'Center Vertically in Container' & 'Trailling space to Container Margin' and width,height constraint
that's all i added constraints, there is no warning and error in storyboard.
i expected as top centered button in portrait and right centered in landscape.
portrait is running normally but preview and simulator show me wrong result when i was change orientation with error log.
like this
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)
(
"\<_UILayoutSupportConstraint:0x7a065db0 V:[_UILayoutGuide:0x7a067440(0)]>",
"<_UILayoutSupportConstraint:0x7a068010 V:|-(0)-[_UILayoutGuide:0x7a067440] (Names: '|':UIView:0x7a0661d0 )>",
"<NSLayoutConstraint:0x7a0680b0 V:[_UILayoutGuide:0x7a067440]-(20)-[UIButton:0x7a066740'Button']>",
"<NSLayoutConstraint:0x7a06d9e0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a0661d0(320)]>",
"<NSLayoutConstraint:0x7a068050 UIView:0x7a0661d0.centerY == UIButton:0x7a066740'Button'.centerY>",
"<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>"
)
Will attempt to recover by breaking constraint "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>
and button fills width and height its container view.
i can't figure out what i did wrong?
am i missing something important about autolayout(with orientation)?
plz help me
(sorry for my bad english. i'm non english native speaker-)
Upvotes: 0
Views: 1358
Reputation: 154513
Your problem is that wCompact|hAny is for iPhones in portrait or landscape. So you end up with conflicting constraints in landscape because all of your constraints apply. You should use wCompact|hRegular for iPhones in portrait.
Upvotes: 2