Contradicting iOS runtime constraint error

552 Views Asked by At

I am getting an unsatisfiable constraints error at runtime (iOS 8.3, XCode 6.3, iPad Air simulator), but the error itself is contradicting with the data that I observe in View Hierarchy debugger.

The runtime error:

"<NSLayoutConstraint:0x7fd7b96a8e30 V:[PushDownView:0x7fd7b96a8890(100)]>",
"<NSLayoutConstraint:0x7fd7b943fa00 V:[UIView:0x7fd7b943f7d0(80)]>",
"<NSLayoutConstraint:0x7fd7b96ac9a0 V:|-(0)-[PushDownView:0x7fd7b96a8890]   (Names: '|':UIView:0x7fd7b943f7d0 )>",
"<NSLayoutConstraint:0x7fd7b96ad3a0 PushDownView:0x7fd7b96a8890.bottom == UIView:0x7fd7b943f7d0.bottom>"

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fd7b96a8e30 V:[PushDownView:0x7fd7b96a8890(100)]>

In Visual Hierarchy debugger, I select the constraints listed above and view them in Object inspector. Here they are in order or appearance:

Address: 0x7fd7b96a8e30
First Item: PushDownView
Relation: Equal
Multiplier: 1
Constant: 100
Priority: 76

Address: 0x7fd7b943fa00
First Item: UIView
Relation: Equal
Multiplier: 1
Constant: 100
Priority: 76

Address: 0x7fd7b96ac9a0
First Item: PushDownView
Relation: Equal
Multiplier: 1
Constant: 0
Priority: 76

Address: 0x7fd7b96ad3a0
First Item: PushDownView
Relation: Equal
Multiplier: 1
Constant: 0
Priority: 76

Look at the constraint 0x7fd7b943fa00 - the error claims it's setting UIView's height to 80. But the Object inspector claims the constant is 100.

As far as I know, I set everything to be 100 in code (but I might be mistaken, so let's stick to facts here).

What am I missing here? Why the error's and the Visual Hierarchy inspector's values are different?

1

There are 1 best solutions below

2
On

I see the next problem on your constraints:

1. <NSLayoutConstraint:0x7fd7b96a8e30 V:[PushDownView:0x7fd7b96a8890(100)]> 

- you set 'height' to 100

2. "<NSLayoutConstraint:0x7fd7b96ac9a0 V:|-(0)-[PushDownView:0x7fd7b96a8890]   (Names: '|':UIView:0x7fd7b943f7d0 )>", 

- the following constraints tell us to 'pin' view to top of superview

3. "<NSLayoutConstraint:0x7fd7b96ad3a0 PushDownView:0x7fd7b96a8890.bottom == UIView:0x7fd7b943f7d0.bottom>" 

- as you see, this constraint pins PushDownView to the bottom of UIView bottom.

We now have conflict between this 3 constraints - it causes when uiview tries to layout it subviews.

Remove height constraint or remove last constraint - it depends upon what you want - if you want PushDownView to scale - remove first, if you need fixed height - remove third