Search code examples
iosuiviewinterface-buildernslayoutconstraint

Size classes not preserving constraints on rotation


All the constraints look ok in IB but when I launch an app and try to rotate the device they just don't work. In horizontal orientation the green view covers all the space on the screen. But the constraints actually work on iPhone 6s Plus

you can see the constraints on this picture

enter image description here

the message from debugger:

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. (

"NSLayoutConstraint:0x7f941a4aa990 V:[UIView:0x7f941a4976a0]-(0)-[UIView:0x7f941a4a9870]",

"NSLayoutConstraint:0x7f941a4aa9e0 UIView:0x7f941a4976a0.height == 0.5*UIView:0x7f941a40ae70.height",

"NSLayoutConstraint:0x7f941a4aa8f0 V:[_UILayoutGuide:0x7f941a4b2310]-(-64)-[UIView:0x7f941a4a9870]",

"NSLayoutConstraint:0x7f941a4aaad0 V:[_UILayoutGuide:0x7f941a4b2310]-(-64)-[UIView:0x7f941a4976a0]",

"NSLayoutConstraint:0x7f941a72aa20 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f941a40ae70(320)]" )

Will attempt to recover by breaking constraint

NSLayoutConstraint:0x7f941a4aa990 V:[UIView:0x7f941a4976a0]-(0)-[UIView:0x7f941a4a9870]


Solution

  • In this situation I just needed a size class wCompact hCompact to set the constraints for iPhones in landscape.