Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What layout constraint is this talking about?

Tags:

xcode

ios

swift

I've read all the SO questions that are similar to this and I'm so lost. I'm getting the following error:

2015-09-14 22:59:40.455 guess-who[60143:9602686] 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:0x7c0f8e30 UIImageView:0x7b6efb60.top == _UILayoutGuide:0x7c0f67a0.top>",
    "<_UILayoutSupportConstraint:0x7c0f8ae0 V:[_UILayoutGuide:0x7c0f67a0(0)]>",
    "<_UILayoutSupportConstraint:0x7c0f0070 _UILayoutGuide:0x7c0f67a0.bottom == UIView:0x7c0f65e0.bottom>",
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6130 h=--& v=--& UIImageView:0x7b6efb60.midY == + 204>",
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6160 h=--& v=--& V:[UIImageView:0x7b6efb60(220)]>",
    "<NSLayoutConstraint:0x7b6f6dc0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7c0f65e0(518)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x7b6f6e20 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7c0f65e0]   (Names: '|':UIView:0x7c0effc0 )>"
)

Will attempt to recover by breaking constraint 
<_UILayoutSupportConstraint:0x7c0f0070 _UILayoutGuide:0x7c0f67a0.bottom == UIView:0x7c0f65e0.bottom>

I've gotten this for a bunch of other constraints which I've successfully solved, but this one is stumping me. I don't know what a UILayoutSupportConstraint is; the documentation is not very thorough. I've looked through the view debugger and UIView:0x7c0f65e0 seems to refer to my main view (although it's the child of a blank view, for some reason?). I'm not able to find anything with 0x7c0f67a0, although that seems to refer to the LayoutGuide, saying their bottoms must be equal. I'm not sure what other tools are available for me to use to figure this out.

EDIT:

Using the View Debugger, I've narrowed it down to one of these two constraints, neither of which I know the source of:

enter image description here

I can't find where either of these gets set. I know everyone's first suggestion is to set translatesAutoresizingMaskIntoConstraints to false, but that destroys my entire layout and I don't know how to fix it.

like image 932
thumbtackthief Avatar asked Sep 15 '15 03:09

thumbtackthief


2 Answers

You could also consider adding accessibility identifiers and constraint identifiers to your views to make your AL logs more legible:

constraintVariableName.identifier = “constraintVariableName”;

In InterfaceBuilder, use the identifier property in the inspector.

self.loginButton.accessibilityLabel = NSLocalizedString("LoginButtonAccessibilityLabel", @"");

These id's will end up in the logs, such as you posted above, replacing things like UIView, UIImageView and UIConstraint with the ids.

like image 116
Michael Avatar answered Sep 18 '22 16:09

Michael


It seems you have given constraints to image view with relation to Superview. So to satisfy you constraint of UILayoutGuide.bottom your constraints are broken. As you have added more or unnecessary constraints which were not required.

Constraints which are getting broken are:

  1. UILayoutGuide.top = UIView.top
  2. UILayoutGuide.height = 0
  3. UILayoutGuide.bottom = UIView.bottom
  4. UIImageView Height constraint
  5. UIImageView Y position
  6. UIView Height constraint
  7. You have given UIView vertical spacing from top is '0' but missing bottom/height constraint.

Try changing the priority of height constraints from 1000 to 750 for UIImageview with height(220),UIView with height(518).

Also you need to check for bottom constraint for "<NSAutoresizingMaskLayoutConstraint:0x7b6f6e20 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7c0f65e0] (Names: '|':UIView:0x7c0effc0 )>"

If it is possible then please attach demo on git for better idea.

Hope it helps.

like image 35
Dhaivat Vyas Avatar answered Sep 21 '22 16:09

Dhaivat Vyas