iOS: Unable to simultaneously satisfy constraints - ios

I've seen the common response to this question of not having constraints set up properly. However, I've worked through all of the ambiguities in Interface Builder, and all constraints seem OK. I'm not sure what to check next. I can't even tell where it is coming from. I'm not setting any constraints in code.
What can I do to figure out where it is coming form?
What can be the cause if Interface Builder doesn't report any ambiguities?
Here's the specific error:
2014-06-28 19:54:36.070 Prayer Feed[4497:60b] 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:0x178290360 H:[UIImageView:0x13ee32490(20)]>",
"<NSLayoutConstraint:0x1782904f0 UITableViewCellContentView:0x178166840.centerX == UIImageView:0x13ee32490.centerX + 62>",
"<NSLayoutConstraint:0x178290540 H:|-(52)-[UIImageView:0x13ee32490] (Names: '|':UITableViewCellContentView:0x178166840 )>",
"<NSAutoresizingMaskLayoutConstraint:0x170286d60 h=--& v=--& H:[UITableViewCellContentView:0x178166840(247)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x178290360 H:[UIImageView:0x13ee32490(20)]>
I know the two place in code where I have a UIImageView constrained to 20x20, but again, IB tells me everything is fine.

This is the part where the problem is:
<NSAutoresizingMaskLayoutConstraint:0x170286d60 h=--& v=--& H:[UITableViewCellContentView:0x178166840(247)]>
This mask needs to be turned off.
I think that mask is off by default for IB elements that have constraints. So I assume you made something in code. You can turn it off in code like this:
contentView.translatesAutoresizingMaskIntoConstraints = NO
If this is really all IB only then I would like to know what code you use around creating table cells.

Related

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];

Autolayout Issues in iOS 7 in Custom TableViewCell

I'm having issues with an Autolayout custom TableViewCell in iOS 7. The cell appears to display correctly, but I get a good deal of debugging console output, such as the following:
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:0x7f9c1a4b8500 V:[UILabel:0x7f9c1a4b72d0]-(0)-[UILabel:0x7f9c1a4b7680]>",
"<NSLayoutConstraint:0x7f9c1a4b8550 V:[UILabel:0x7f9c1a4b7680]-(0)-[UILabel:0x7f9c1a488910]>",
"<NSLayoutConstraint:0x7f9c1a4b85c0 V:[UILabel:0x7f9c1a488910]-(NSSpace(20))-| (Names: '|':UITableViewCellContentView:0x7f9c1a4b66d0 )>",
"<NSLayoutConstraint:0x7f9c1a4b87f0 V:|-(NSSpace(20))-[UILabel:0x7f9c1a4b6f00] (Names: '|':UITableViewCellContentView:0x7f9c1a4b66d0 )>",
"<NSLayoutConstraint:0x7f9c1a4b8840 V:[UILabel:0x7f9c1a4b6f00]-(NSSpace(8))-[UILabel:0x7f9c1a4b72d0]>",
"<NSAutoresizingMaskLayoutConstraint:0x7f9c1a4a70e0 h=--& v=--& V:[UITableViewCellContentView:0x7f9c1a4b66d0(44)]>"
)
I only get this output in iOS 7, and I see it on all of my custom table view cells, across multiple view controllers. I have followed all of the steps in this post:(Using Auto Layout in UITableView for dynamic cell layouts & variable row heights). I have tried adjusting the AutoresizingMask of the content view in these cells, but it does not stop these errors from appearing. I would greatly appreciate some advice on fixing these errors. Thanks!
The last one,
"NSAutoresizingMaskLayoutConstraint:0x7f9c1a4a70e0 h=--& v=--& V:[UITableViewCellContentView:0x7f9c1a4b66d0(44)]"
could indicate that in the tableviewcell the translatesAutoresizingMaskIntoConstraints property is set to YES. If this is the case try to set it to NO to avoid conflicts between your constraints and the automatic ones.
This means that you have constraints that conflict, and it is picking to satisfy one since they cannot all be satisfied.
Usually this means that you either have:
1)Constraints you know will not be satisfied simultaneously such as a minimum size or offset combined with a percentage or ratio. In this case all you need to do is reduce the priority of the one you want to break first.
Or, 2) duplicate constraints worded differently(center vertically, but also trailing space, etc) this one is harder for me to remotely diagnose, so posting the constraint would be important.
If the particular constraints are not that important to you (AKA you didn't spend that long adding them) then removing them all, adding suggested, and working from there is a very valid starting point.

Autolayout unable to simultaneously satisfy constrains [duplicate]

This question already has answers here:
Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint
(17 answers)
Closed 8 years ago.
I always create my views in code and so have never used auto layout (until now). The reason behind not using nibs is because I like the code better and it's simpler to maintain via GitHub etc, but enough about that.
I have a situation where I have three labels on the screen placed next to each other. Like so: |Label1| - some space - |Label2| - some space - |Label3|. Some space is let's say 15pts. Now what I would like to accomplish is that when I change the text of the labels I will call sizeToFit on them and would like that they would remain 10pts apart from each other. I know I could to this with a bit of math which is not even hard but I think that auto layout will be easier and more understandable and I will learn something new along the way. So what I did is:
Alloc & init all the labels
Give each label a frame (and set font, text color, etc)
Add the labels as a subview
Then I tried to set up the constraints between them like so:
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"[label1]-15-[label2]-15-[label3]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(label1, label2, label3)];
[self addConstraints:constraints]; //Im subclassing an UIView that's why self
But I get an error saying:
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:0x14c14110 H:[UILabel:0x14c12ab0]-(15)-[UILabel:0x14c12f80]>",
"<NSAutoresizingMaskLayoutConstraint:0x14c08b00 h=--& v=--& UILabel:0x14c12ab0.midX == + 195>",
"<NSAutoresizingMaskLayoutConstraint:0x14c0dd90 h=--& v=--& H:[UILabel:0x14c12ab0(40)]>",
"<NSAutoresizingMaskLayoutConstraint:0x14c1c170 h=--& v=--& UILabel:0x14c12f80.midX == + 237.5>",
"<NSAutoresizingMaskLayoutConstraint:0x14c12f00 h=--& v=--& H:[UILabel:0x14c12f80(40)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x14c14110 H:[UILabel:0x14c12ab0]-(15)-[UILabel:0x14c12f80]>
Even if I try to do this just on the label 2 and 3 the same thing happens. I do not fully understand what the NSLog is saying.
Any help would be much appreciated. Also if you have any good links on where to "decode" those h=--& v=--& UILabel:0x14c12f80.midX == + 237.5 things would be awesome.
The h= and v= are the signatures of autoresizing masks being translated into constraints. Did you forget to set translatesAutoResizingMasksToConstraints = NO on one of your views?

Unable to simultaneously satisfy constraints, where is it coming from?

I have this warning when building my app. I'm using a storyboard, but all constraints are proper over there.. I don't know where else I have to look..
2014-04-29 14:18:54.072 gTicket[1540:60b] 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:0x16593a90 V:[UIView:0x165a1dd0(429)]>",
"<NSLayoutConstraint:0x165b3c50 V:[UILabel:0x165b3d80(20)]>",
"<NSLayoutConstraint:0x165b37c0 V:[UIView:0x165945a0(52)]>",
"<NSLayoutConstraint:0x165ac960 V:[_UILayoutGuide:0x165a8670]-(36)-[UIView:0x165a1dd0]>",
"<NSLayoutConstraint:0x165a9060 V:[UIView:0x165a1dd0]-(14)-[UILabel:0x165b3d80]>",
"<NSLayoutConstraint:0x165b50d0 V:[UILabel:0x165b3d80]-(16)-[UIView:0x165945a0]>",
"<NSLayoutConstraint:0x165a1e80 V:[UIView:0x165945a0]-(1)-[_UILayoutGuide:0x165adfc0]>",
"<_UILayoutSupportConstraint:0x165adf00 V:[_UILayoutGuide:0x165a8670(0)]>",
"<_UILayoutSupportConstraint:0x165ae3b0 V:|-(0)-[_UILayoutGuide:0x165a8670] (Names: '|':UIView:0x165a6940 )>",
"<_UILayoutSupportConstraint:0x1659c120 V:[_UILayoutGuide:0x165adfc0(0)]>",
"<_UILayoutSupportConstraint:0x165a12d0 _UILayoutGuide:0x165adfc0.bottom == UIView:0x165a6940.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x165baf00 h=--& v=--& V:[UIView:0x165a6940(431)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x16593a90 V:[UIView:0x165a1dd0(429)]>
Is it possible to determine which UILabel and which view it is complaining about?

Autolayout shows warning message

i have some Problems with autolayout. Everything gets shown correct and everything works fine but i get some Warning Message in the Command Line:
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:0xb6a60f0 H:[UIImageView:0xb645e40(75)]>",
"<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>",
"<NSLayoutConstraint:0xb6aaea0 H:|-(10)-[UIImageView:0xb645e40] (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6c85c0 H:[UIView:0xb6c7350]-(7)-| (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6d2270 H:[UIImageView:0xb645e40]-(8)-[UIView:0xb6c7350]>",
"<NSAutoresizingMaskLayoutConstraint:0xb6abd20 h=--& v=--& H:[UITableViewCellContentView:0xb6c1590(300)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>
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.
This is how my nib File looks:
As you can see its a TableViewCell and i´m using a View (Sample Text) with a TextView(for iOS7) and a AttributedTextView (for iOS6)!
Whats the Problem?
The problem is that you have conflicting constraints... Auto Layouts can be a pain in the .... sometimes.
When this happens to me, i usually clear all the constraints, and start all over by choosing clear all constraints.
You can also choose to "Add missing constraints" after that, and hope that XCode will automatically know what you want to do.. actually it's a 50-50 chance that XCode will get it right.
From your screen shot, it looks like you have too many constraints, so another option will be to try to remove then one by one, and to catch those "conflicting" constraints.
Set for each view translatesAutoresizingMaskIntoConstraints = NO; That is what he is trying to tell you. During runtime you have your contraints and the generic ones. Guess we will see this property switching to NO as default in a upcomming iOS version.

Resources