NSLayoutConstraint reporting wrong constraint inconsistency?

I have the following view structure

[self view]

  • [self stretchView]
  • [[self slidingViewController] view]
    • UISegmentedControl
    • CPTGraphHostingView

The debugger shows the following dimensions (before layouting):

po [self view]

<UIView: 0x18c905b0; frame = (0 32; 480 288); autoresize = W+H; layer = <CALayer: 0x18ca5970>>

po [self stretchView]

<UIView: 0x18c8c250; frame = (0 0; 240 288); layer = <CALayer: 0x18cabf90>>

po [[self slidingViewController] view]

<UIView: 0x158ac920; frame = (240 0; 240 288); autoresize = W+H; gestureRecognizers = <NSArray: 0x18cf0b00>; layer = <CALayer: 0x18973fd0>>

po [[[self slidingViewController] view] subviews]

<__NSArrayM 0x18cf0b50>(

<UISegmentedControl: 0x189bfe10; frame = (50.5 20; 139 29); opaque = NO; layer = <CALayer: 0x189c1220>>,

<CPTGraphHostingView: 0x189ba8e0; frame = (0 68; 240 220); gestureRecognizers = <NSArray: 0x1897c900>; layer = <CALayer: 0x158ac8b0>>

)


During layouting I get the following error message:


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:0x188d19b0 V:|-(20)-[UISegmentedControl:0x189bfe10] (Names: '|':UIView:0x158ac920 )>",

"<NSLayoutConstraint:0x18cf06b0 CPTGraphHostingView:0x189ba8e0.bottom == UIView:0x158ac920.bottom>",

"<NSLayoutConstraint:0x18cf0720 V:[UISegmentedControl:0x189bfe10]-(20)-[CPTGraphHostingView:0x189ba8e0]>",

"<NSLayoutConstraint:0x15f5b170 V:|-(0)-[UIView:0x18c8c250] (Names: '|':UIView:0x18c905b0 )>",

"<NSLayoutConstraint:0x18cf4f20 UIView:0x18c8c250.height == UIView:0x18c905b0.height>",

"<NSLayoutConstraint:0x18ca8c70 V:[UIView:0x18c8c250]-(0)-[UIView:0x158ac920]>",

"<NSLayoutConstraint:0x15fd89b0 UIView:0x158ac920.bottom == UIView:0x18c905b0.bottom>"

)

Will attempt to recover by breaking constraint

<NSLayoutConstraint:0x18cf0720 V:[UISegmentedControl:0x189bfe10]-(20)-[CPTGraphHostingView:0x189ba8e0]>


The first layout constraint sets the segmented control 20 points below [[self slidingViewController] view]. The third one sets the top of CPTGraphHostingView to 20 points below the segmented control (with the current dimensions this results in 20+29+20+220 = 289 which is slightly larger than 288.

BUT: the second layout statement should also change the size of the CPTGraphHostingView by modifying the bottom.


Therefore, I do not understand why I get this error message.

BTW: The layouting works.


Best regards,

Hartwig

Replies

I am an old programer, don't want to learn the new SWIFT (a much simpler and easy way to write App)

I don't want to learn the new Layout with Constraint Method.

In same situration, like you, most of the time go back to the old ways, disable Auto Constraint.

But finally, give in.

My experiences:

use XCode constraint suggestions, (may not be what you want, Bottom RHS)

On LHS pane, you will see list of constraints created by Xcode,

Disable those you donot want or need, (donot delete it)

Change those constraints you do need,

Hope this will help.

NSLayoutConstraint

As you note, the size of the layout you've specified is taller than the layout that appears to be possible. Because all of your constraints appear to be possible, one of them must be broken in order to provide any kind of layout at all – hence the message.


In other circumstances, a different constraint may be broken instead, which would result in a different, potentially broken, layout.


As such you should fix your constraints, such as by making one of them non-required (perhaps the 20pt spacing between the segmented control and the graph hosting view) or make it so that your view controller's view can be large enough to display its contents at the size they are requesting.

In addition to Rincewind,

Use Xcode auto constraint, everywhere on your problematic xib, will eliminate all errors!

But UI will not appear as you would like.

But this is the first step to fix the errors.

Then, adjust each set of contraints, until you got it to work as you want.

Do not change more than 1 set of constraint at same time.

Hi Rincewind,


actually, the layout only seems to be taller than what appears to be possible. If the mathematics is done correctly the layout will fit. This is my whole problem.