Unable to simultaneously satisfy constraints. Leading and Trailing constraints conflicts - ios

Can somebody help me understand these errors and and suggest how to go about solving them?
2014-09-19 08:52:45.812 Zazzle[23292:1834589] 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:0x7c0ba1e0 H:|-(8)-[UIView:0x7c0bb900] (Names: '|':UIView:0x7c0b6c20 )>",
"<NSLayoutConstraint:0x7c0ba210 H:[UIView:0x7c0bb900]-(8)-| (Names: '|':UIView:0x7c0b6c20 )>",
"<NSLayoutConstraint:0x7c0942e0 UIView:0x7c0b6c20.left == UIView:0x7c0bbfa0.left>",
"<NSLayoutConstraint:0x7c0c03e0 UIView:0x7c0b6c20.right == UIView:0x7c0bbfa0.right>",
"<NSLayoutConstraint:0x7c635250 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7c0bbfa0(2)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7c0ba210 H:[UIView:0x7c0bb900]-(8)-| (Names: '|':UIView:0x7c0b6c20 )>

fromFollow the below steps
Check the constraints of a UiObject and remove any constraints that duplicated, from size inspector of Xcode.
If there is no duplication,find out exact constraint that cause the problem
Try to change the priority of constraint from default required(1000) to high(750).

The conflict is right there: the first two constraints set the subview's leading and trailing values to be 8 pixels away from the containing view controller's left and right edges, while the third and fourth lines set them to be exactly even with the containing view's edges. Remove one pair or the other, or, as #dasdom said, lower the priorities of one of the constraint pairs.

Related

What exactly does lowering the priority of a constraint do?

I am constructing a variable size table view within another view. The table view should not scroll so I am programmatically determining its content size and adjusting a height constraint so that the table view always fits its content.
The problem I run into is a warning about a broken constraint:
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)
(
"<NSAutoresizingMaskLayoutConstraint:0x170498b00 h=--& v=--& UIView:0x1024f2c90.height == 322 (active)>",
"<NSLayoutConstraint:0x17428d660 UITableView:0x103152400.height == 322 (active)>",
"<NSLayoutConstraint:0x174482da0 V:[UITableView:0x103152400]-(27)-| (active, names: '|':UIView:0x1024f2c90 )>",
"<NSLayoutConstraint:0x17429da10 V:|-(16)-[UITableView:0x103152400] (active, names: '|':UIView:0x1024f2c90 )>"
)
To fix this, I tried 2 things:
Set translatesAutoresizingMaskIntoConstraints = false. This causes everything to go haywire with the table view.
Lower the priority of the adjustable height constraint to 999.
Point 2 solves my problem and I'm able to adjust the height of the view using the lower priority constraint. But, I don't understand why this works.
So, how does Auto Layout interpret the priority of a constraint? I would've expected the NSAutoresizingMaskLayoutConstraint to take over the lower priority constraint and make it so I could not resize the view using the constraint.
To answer the question in the headline: Lowering the priority of a constraint tells the autolayout that the constraint is less important than all constraints with a higher priority.
This means that if two constraints are conflicting autolayout will use the one with the highest priority and disregard the other.
If two required constraints with identical priorities conflict, you will have an error message like the one you describe.
Since you are setting the height at run time I would select the height/vertical constraint in IB you don't need at run time and turn the 'Placeholder' for the constraint to 'Remove at build time', this should remove your warnings.
The priority setting determines when there are conflicting constraints which one will be used.

What layout constraint is this talking about?

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:
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.
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.
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:
UILayoutGuide.top = UIView.top
UILayoutGuide.height = 0
UILayoutGuide.bottom = UIView.bottom
UIImageView Height constraint
UIImageView Y position
UIView Height constraint
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.
Disabling translatesAutoresizingMaskIntoConstraints wrecks your layout because some of your stacked elements have no explicit height/width set (PlayAgain, cat, frame) and are based off the image contents.
Your example project isn't runnable out of the box, so I can't inspect the runtime layout. However, I'd start by specifying the height of those elements so there are fewer auto constraints. It also looks like you're changing a lot of the constraints at runtime, so you need to be cautious about altering constraints that will conflict with each other. Make sure that the layout's happy before you start constraint-constant fiddling!
Use this following Line. It may be help you.
[view setTranslatesAutoresizingMaskIntoConstraints:NO];

Contraints greyed-out in Xcode

I am trying to debug+understand autolayout constraints and I notice that when debugging the view with xcode (using the cool layer thing) I noticed that on one element in the view the constraints look like this
and the view is indeed ignoring these constraints.
All constraints have the same priority (1000) since I want them all. All constraints were made with interface builder and not through code, and there are not warning or conflicts in IB.
But in runtime I do see this
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:0x79684f10 V:[UIImageView:0x79686800(>=160)]>",
"<NSLayoutConstraint:0x7968a310 V:[UIImageView:0x79686800]-(130.5)-| (Names: '|':UIView:0x79686790 )>",
"<NSLayoutConstraint:0x7968a340 V:|-(0)-[UIImageView:0x79686800] (Names: '|':UIView:0x79686790 )>",
"<NSLayoutConstraint:0x796997b0 'UIView-Encapsulated-Layout-Height' V:[CoverCell:0x79686570(192)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7969cd30 h=-&- v=-&- UIView:0x79686790.height == CoverCell:0x79686570.height>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x79684f10 V:[UIImageView:0x79686800(>=160)]>
So from this I understand that some rules conflict, but I'm not sure how to read this
the >=160 is a rule on the UIImageView so it would have height of atleast 160 and 130.5 is the bottom padding of the imageview (so when using systemLayoutSizeFittingSize:UILayoutFittingCompressedSize the height won't be 0. So the minimum height for the entire cell is 160+130.5)
The rest of the error I don't understand.
What is wrong with the constraints and why do constraint conflicts occur in runtime and not in IB?
XCode 6 now supports different layouts. This greyed out constraints exist in Compact Width | Any Height layout, for example, but you currently editing Any Width | Any Height.
More detailed:
Storyboard View Elements Greyed Out
It depends. If you don't use size classes the grey ones are the removed ones. And you need to remove them second time. No matter how stupid it sounds.
If you use size classes, it means that your current size class is different than for greyed constraint. (however the first scenario is also possible...)
In your case it looks like this is the first case. You need to remove greyed constraints once again.

Correctly define constraint for UITableViewCell resizing

i'm currently facing this problem, i need to define a dynamic height UITableViewCell.
The red lines correspond to resizable views (will grow vertically), the blue label have 3 constraints: two for each immediate red views above (>= 8), one more with 170 and lower priority to superview.
The green one has a bottom constraint to the superview (5)
When i try to run my code, it gives me this:
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:0x19d65bb0 V:[UIView:0x19d9a9a0(5)]>",
"<NSLayoutConstraint:0x19d667d0 V:[UILabel:0x19de4180(19)]>",
"<NSLayoutConstraint:0x19d5ba70 V:[UILabel:0x19d61870(19)]>",
"<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>",
"<NSLayoutConstraint:0x19d35d30 V:[UIView:0x19d36130(0)]>",
"<NSLayoutConstraint:0x19e7b310 V:|-(5)-[UILabel:0x19d6b520] (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSLayoutConstraint:0x17d0b060 V:[UILabel:0x19d6b520]-(5)-[UIView:0x19d9a9a0]>",
"<NSLayoutConstraint:0x17d0a480 V:[UIView:0x19d9a9a0]-(8)-[UILabel:0x19de4180]>",
"<NSLayoutConstraint:0x17d0c920 V:[UILabel:0x19de4180]-(8)-[UILabel:0x19d61870]>",
"<NSLayoutConstraint:0x17d0a100 V:[UILabel:0x19d61870]-(8)-[UIView:0x19d839e0]>",
"<NSLayoutConstraint:0x17d11ad0 V:[UIView:0x19d839e0]-(8)-[UILabel:0x19d36e80]>",
"<NSLayoutConstraint:0x19e742a0 V:[UILabel:0x19d36e80]-(8)-[UILabel:0x19d36770]>",
"<NSLayoutConstraint:0x19ed84a0 V:[UILabel:0x19d36770]-(8)-[UIView:0x19d36130]>",
"<NSLayoutConstraint:0x19e76410 V:[UIView:0x19d36130]-(>=8)-[UILabel:0x19d35560]>",
"<NSLayoutConstraint:0x19ed8af0 V:[UILabel:0x19d35560]-(8)-[UITextView:0x1832ba00]>",
"<NSLayoutConstraint:0x19e7abf0 V:[UITextView:0x1832ba00]-(8)-[UILabel:0x19e7d890]>",
"<NSLayoutConstraint:0x19e83d90 V:[UILabel:0x19e7d890]-(8)-[UITextView:0x18a95e00]>",
"<NSLayoutConstraint:0x19e7b520 V:[UITextView:0x18a95e00]-(5)-| (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSAutoresizingMaskLayoutConstraint:0x19d46fc0 h=--& v=--& V:[UITableViewCellContentView:0x19d97580(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
So, the question is:
What is the correct way of achieving this???
Are u using storyboard, if yes, simple go to Editor->Resolve Auto Layout Issues->Clear All Constraints In ........ Controller, and then Add Missing Constraints In ...... Controller
It will help you fix the problem of breaking contrainsts between view

Unable to simultaneously satisfy constraints when animating

I have six user constraints setup with IB that look like this:
H:|-(593)-[UIView(411)]-(20)-|
V:|-(20)-[UIView(288)]-(396)-|
I grow and shrink the view by changing the constraints and then calling layoutIfNeeded. For example, to grow the view I will do:
H:|-(20)-[UIView(984)]-(20)-|
V:|-(20)-[UIView(663)]-(20)-|
And then call
[UIView animateWithDuration:.5 animations:^{
[self.view layoutIfNeeded];
}];
This technique grows and shrinks my view, and it looks nice, but I'm given a rather confusing warning:
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:0x148d5af0 H:[UIView:0x148d4e50(411)]>",
"<NSLayoutConstraint:0x148cc940 H:[UITableView:0xace7600(319)]>",
"<NSLayoutConstraint:0x148ce040 H:|-(NSSpace(20))-[UITableView:0xacd4e00] (Names: '|':UIView:0x148cddd0 )>",
"<NSLayoutConstraint:0x148cdf00 H:[UITableView:0xace7600]-(NSSpace(20))-| (Names: '|':UIView:0x148cddd0 )>",
"<NSLayoutConstraint:0x148cdea0 H:[UITableView:0xacd4e00]-(NSSpace(8))-[UITableView:0xace7600]>",
"<NSLayoutConstraint:0x148d4c10 UIView:0x148cddd0.trailing == UIView:0x148cdd40.trailing>",
"<NSLayoutConstraint:0x148d4b90 H:|-(0)-[UIView:0x148cddd0] (Names: '|':UIView:0x148cdd40 )>",
"<NSLayoutConstraint:0x148d6020 H:|-(320)-[UIView:0x148cdd40] (Names: '|':UIView:0x148cd330 )>",
"<NSLayoutConstraint:0x148d5fa0 UIView:0x148cdd40.trailing == UIView:0x148cd330.trailing>",
"<NSLayoutConstraint:0x148d5f60 H:[UIView:0x148d4e50]-(NSSpace(20))-| (Names: '|':UIView:0x148cd330 )>",
"<NSLayoutConstraint:0x148d5ee0 H:|-(20)-[UIView:0x148d4e50] (Names: '|':UIView:0x148cd330 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x148cc940 H:[UITableView:0xace7600(319)]>
Now all of these constraints are generated by IB. I've double^(triple!) checked this. I've put these constraints together with a pen and paper and have gotten this:
UIView_A H:[-(20)-[UIView_E]-(20)-] and H:[-(320)-(UIView_B)
UIView_B H:[-(0)-[UIView_D]
UIView_C H:[UIView_C(411)]
UIView_D H:[-(20)-[UITableView_F]-[UITableView_G(319)]-(20)-]
I don't understand how these constraints can't be satisfied. They look fine. I don't change them and they're generated by IB. Aren't constraints generated by IB automatically satisfiable?
Or, at a minimum, is there a way to stop warnings? It behaves perfectly and I don't need to see that it's breaking a constraint that doesn't seem to do anything anyway.
This constraint:
H:[UITableView:0xace7600(319)]>"
seems to be an impediment for the system resolution.
Can you remove it ?
So, it turns out, the order at which I change constraints matters.
To grow the view, I will
Increase the width: H:|-(593)-[UIView(984)]-(20)-|
Decrease the leading space: H:|-(20)-[UIView(984)]-(20)-|
This produces no warnings. However, if I do this in the opposite order, I'll get a warning:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints ...
...Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1567f650 H:[UITableView:0x119e6200(319)]>
When shrinking the view, I copied the code that increased the width (with the same order) and just changed the values. That gave me the warning I posted in my original question. When I switched the order for shrinking, the warnings disappeared.
Why is this the case? I don't know. I'll update as I discover more.
I got same message, and I finally got it why it happens,
My solution is: Do not let any object FLIP OVER during at any moment of the animation.
In other words, contraints are should be OUTside of any object,
but sometimes constraints are inside during animation, not like our expection.
In another words, do not let top margin invade bottom margin due to constraint animation.
For example,
top constraint: topA = initially 100
[Box A]
bottom constraint: botA = initially 150
now, if you set like below and animate,
topA = 300
botA = 25
then error should occur,
why: thread invades the bottom margin BEFORE bottom margin go down.
So,
You'd rather change the ORDER,
botA = 25
topA = 300
Then error will disappear because bottom constraint would preserve the height of the mass and next top constraint would shrink the object's height not invading the bottom margin.
*Point:
Let the object have width and height greater than 0 CONTINUALLY even during animation,
not interrupted by constraints change.
I hope I helped you.

Resources