Reputation: 10139
I am having some issues with constraints which I can't get my head around. I think I would find it really helpful if I understood the error messages (specifically relating to NSLayoutConstraints
) in the console window better. Here is an example:
I have this constraint:
NSLayoutConstraint(item: mainView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: 0)
Which makes sense to me, I want to make mainView
the exact same height as self.view
. However this generates the 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:0x7a94fa10 UIView:0x7a9f95c0.height == UIView:0x7a9d1660.height>",
"<NSAutoresizingMaskLayoutConstraint:0x7a9488a0 h=--& v=--& V:[UIView:0x7a9f95c0(110)]>",
"<NSLayoutConstraint:0x7a948490 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a9d1660(430)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a94fa10 UIView:0x7a9f95c0.height == UIView:0x7a9d1660.height>
I have commented out all the other constraints except for this one, and yet I still get this error. Am I right in thinking the constraint is conflicting with itself?
Can anyone point me in the right direction with how to fix this problem?
Most importantly, if anyone can help me understand these NSLayoutConstraint
error messages that would be extremely helpful.
--
Please note I am using Swift here, but I don't mind if the answers are in Objective C.
Upvotes: 1
Views: 1211
Reputation: 1144
mainView.translatesAutoresizingMaskIntoConstraints = NO. // ObjC mainView.translatesAutoresizingMaskIntoConstraints = false. // Swift
It will work!
thx
Upvotes: 4