Contraints greyed-out in Xcode - ios

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.

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

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 contraint error

So this autolayout error. Which I know why it is there but I am not sure how can I fix it. As with error its clear that its not able to resolve the constraints.
In portrait mode all 47 episode are listed and can be scrolled to. But in landscape mode it cant, which is clear as height of table is not changing thats way its is still down there but can't scroll to it.
So this is how I have setup.
Where as view controller has two view which works as placeholder upper is of for iAds and lower is holding table view. Idea was behind this. if ad is not loaded I will set height of View to zero which holds iADBanner. So that Table view takes up all space. (Got this idea from Ray Wenderlich's app level me up.) I was struggling with auto layout initially but I made it right so that view are taking up all width when sim goes to portrait mode. but somehow I am not able to fix the height of view which holds tableView.
Below are the screenshot of constraints.
I tried to be as descriptive as I can. but I am looking for more than just answer. I want to get to know this completely so that I will most likely won't have problem in future. I have finished raywenderlich tutorial already. So Any other pointer would be very much appreciate along with the answer.
2014-07-30 21:40:37.326 Test[85608: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:0xa5afbc0 UIView:0xa69b7d0.width == 0.682303*UIView:0xa69b830.height>",
"<NSLayoutConstraint:0xa5afc80 V:|-(50)-[UIView:0xa69b830] (Names: '|':UIView:0xa69b7d0 )>",
"<NSLayoutConstraint:0xa5afdc0 V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410]>",
"<_UILayoutSupportConstraint:0xa5a7d20 V:[_UILayoutGuide:0xa5a8410(0)]>",
"<_UILayoutSupportConstraint:0xa5af490 _UILayoutGuide:0xa5a8410.bottom == UIView:0xa69b7d0.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0xa792d10 h=--& v=--& H:[UIView:0xa69b7d0(480)]>",
"<NSAutoresizingMaskLayoutConstraint:0xa792dd0 h=--& v=--& V:[UIView:0xa69b7d0(271)]>" )
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xa5afdc0 V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410]>
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.
The list of constraints in the error log is the key to understanding this type of problem. What you want to do is look at it carefully to correlate which lines refer to which constraints in your code/ui builder, and which hexadecimal address refers to which view.
V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410] is a constraint setting the bottom of a UIView to a layout guide, so most likely that's the last constraint in your screenshot "Vertical Space - Bottom layout guide - TableVi..." (presumably that's TableViewHolder truncated). That means UIView:0xa69b830 is your TableViewHolder.
V:|-(50)-[UIView:0xa69b830] (Names: '|':UIView:0xa69b7d0 ) is the constraint tying the top of TableViewHolder 50px from its superview, which must be UIView:0xa69b7d0.
UIView:0xa69b7d0.width == 0.682303*UIView:0xa69b830.height looks like an aspect ratio constraint between the superview width and the TableViewHolder height.
h=--& v=--& H:[UIView:0xa69b7d0(480)] and h=--& v=--& V:[UIView:0xa69b7d0(271)] are constraints on the superview that's derived from its autoresizingMask, where the width=480px, height=271px, and their top/left/width/height are fixed (based on h=--& v=--&). This is sort of the standard setup for the root view of a view controller — it's dimensions are managed manually by the view controller to fill the screen.
So once you have all that, you can see what the problem is: the superview has fixed dimensions 480x271. Meanwhile, TableViewHolder's height is being dictated by multiple conflicting constraints:
#1 and #2 are trying to stretch it vertically to fill its superview with a 50px margin at the top, so height = 271-50 = 221px.
#3 is trying to set the height as a ratio of the superview's width: height = 480/0.6823 = 703.5px
221 != 730.5!
Something's gotta give, and the OS just happened to pick #1, so the bottom of TableViewHolder extends past the bottom of the layout guide, making it stick out past the edge of the screen and inaccessible.
Your fix will likely involve getting rid of that aspect ratio constraint, but there might be other issues that appear once you fix that. Good luck!

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