I'm doing an iPhone app using Xcode 6
My problem here is, I add a constraint to an image, and all is fine, and than I try to add another constraint on a smaller screen and I get the error on the bottom of this message.
Is there any way of adding different constraints according to the size we are at? That is what it feels like on Xcode on the wAny hAny area, but for some reason it just doesn't work.
2014-10-06 17:41:45.059 testapp[2623:26567] 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) (
"",
"",
"",
"" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints
to catch this in the debugger. The methods in the
UIConstraintBasedLayoutDebugging category on UIView listed in
may also be helpful.
When a constraint receives a negative value or the value that contradicts with other values, it spits an error. For instance:
You have an image, that has height 500 and the constraint attached to it's bottom
You modify this constraint such a way that the image gets smaller and smaller (constant value)
Eventually image will have negative value, which is impossible. And the rest of the constraints will also "suffer"
Make sure that the height of the parent view is greater than the height of the image. Hopefully the example above will make you better understand the issue in general.
Related
I have some issues with auto layout, where the console says there are conflicting constraints. However, when Xcode attempts to fix the issue, everything works as intended. In the console it reports
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe578db22f0 V:[UILabel:0x7fe578d9b200'Label'(32)]>
I want to find the constraint mentioned: "0x7fe578db22f0" and delete it manually.
Is there anyway to find it by using that hex code? And if not, can anyone suggest a way to fix my issue? I have a lot of constraints and it would be very difficult to go through and test each one.
If the question is merely how to identify which view that constraint is associated with, the easiest way is probably using the view debugger. So, run the app and click on the "debug view hierarchy" button. Then examine your view hierarchy in the left panel (narrowing it down by searching for view type, if you want), until you see a constraint that looks like the one in question. And by choosing the object inspector, you can confirm the address of the constraint in question.
Now that you've identified the precise constraint and view in question, the tracking down of its creation in the app should be much easier.
Add UIViewAlertForUnsatisfiableConstraints symbolic breakpoint help you debug autolayout easier !
When I go to the screen that is causing this error, their is a white screen. It should have a website on it. Ive read the error but I don't know how to fix it. Any help? The Picture shows what it says.
Update: The warnings have went away but I still get a white screen.
Look underneath the error and read what it says:
Constraint referencing items turned off in current configuration. Turn
off this constraint in the current configuration.
It seems as though you had some items in your storyboarrd window that had some constraints set on them, and then those items were deleted. The constraints seem to still be set.
If you remove those constraints, this error should disappear.
If you cannot find those constraints, refer to this question's answer:
Xcode Storyboard warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration
Loving XCode 6/iOS8's new way (using size classes) of doing Autolayouting (despite it being a pretty hard puzzle to solve at times).
But how does one reset one of the size classes back to Any/Any?
Set you size class to wAny hAny
Now you should see constraints installed outside this size class as greyed out in the pane on the left:
Select this constraint in the list and in the detail inspector pane on the right you should see this:
Here you see I installed a wRegular hAny constraint.
Hit the little x to delete this constraint in this size class.
Repeat for any other constraints you have.
Once these constraints are no longer installed in any size classes you can select and delete them in the left pane.
When you click on the Width/Height, take your cursor to the middle square and select it. That will set it at Any/Any.
Edit: I think I may have misunderstood. If, for example, you are working in wCompact hRegular, and you don't want those changes anymore and you want it to "inherit" from Any/Any, then you'll have to go about either uninstalling or deleting the constraints you created specifically for that size class. When you have your view controller outline showing, and the constraints appearing, the ones not grayed out are active for that size class. Check each one to see if any are specific to the size class you're working in (such as wCompact hRegular).
You can also uninstall or delete any additional UI objects you added to that size class specifically.
Hope that helps.
Sometimes I keep getting errors like these - without any hint to which TextView or Button is meant:
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:0x11d748d0 V:[UITextView:0xc1bb000(65)]>",
"<NSLayoutConstraint:0x11d77620 V:[UIButton:0x11d71cf0(44)]>",
"<NSLayoutConstraint:0x11d7be30 V:[UIButton:0x11d79e70(43)]>",
"<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000] (Names: '|':UIView:0xa1afba0 )>",
"<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>",
"<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>",
"<NSLayoutConstraint:0xa199cb0 V:|-(40)-[UIButton:0x11d79e70] (Names: '|':UIView:0xa1afba0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>
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.
Is there a way to identify the constraint in the code that is causing the crash?
The text:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x11d748d0 V:[UITextView:0xc1bb000(65)]>
unfortunately doesn't help much, since I do not have any idea which constraint this is in code
You read them like this:
<NSLayoutConstraint:0x11d748d0 V: [UITextView:0xc1bb000(65)]>
^ Constraint type ^ Address ^Axis ^Description in VFL
(of constraint)
So this is a constraint forcing the textview to be 65 points high. In there you also have a constraint pinning this text view to 134 points from its superview's top edge:
<NSLayoutConstraint:0xa1980d0 V:|-(134)-[UITextView:0xc1bb000] (Names: '|':UIView:0xa1afba0 )>
And a constraint pinning the Y center of the text view to the Y center of a button:
<NSLayoutConstraint:0xa199ed0 UITextView:0xc1bb000.centerY == UIButton:0x11d71cf0.centerY>
And a constraint pinning the button itself to a specific vertical location:
<NSLayoutConstraint:0xa199e50 V:[UIButton:0x11d79e70]-(61)-[UIButton:0x11d71cf0]>
It is likely that you didn't want all these constraints. Here you have two constraints that are trying to position the text view vertically (based from the button, and based on absolute spacing from the top of the superview).
Somewhere in your app you must have a view with a text field and two buttons. If you break on all exceptions you can log out the various addresses given in the log and find out the superviews and so on if you're not sure, but hopefully you'll be able to work it out from this.
Sometimes it is helpful to copy the log into a text editor and find / replace the addresses with words so that it is easier to read.
I'm building a simple application using autolayout, and I've run into a strange situation. I place a Text Field in an empty part of a large open view so it's not affected by anything but the super view, but when I try to modify the "Width" constraint to be >= instead of ==, it creates a new constraint and refuses to modify the old one. I can't delete it, or change any of its attributes, because it just creates a new one.
Here is a comparison of the two constraints, the purple one being the stubborn one, and the blue one being the newly created one.
Why is the purple rounded one not modifiable?
I have worked around the presence of undeletable-but-unwanted constraints in IB by setting their priority to 1. Doesn't seem like the Right Thing to do, but sometimes I'm not smart enough to be a Cocoa developer.
My problem had to do with with fact that there weren't enough other constraints added that the width would ever be forced to change. When I added more other constraints (such as leading and trailing space), I was then able to alter the purple constraint (in fact, it disappeared and I had to add my own).
It seems strange that you cannot add your own constraints unless there is a possibility of them being broken, but I guess that's the way it's been integrated into IB in some cases.
Lowering the priority of the purple constraints will also make them editable.
I had a similar scenario, where there were two multiline labels. Based on the content size, both should resize.
When the first label resized, it was overwriting the second label because the second one had a Vertical Space constraint( "Top Space to SuperView = 40". it's a system default constraint - purple colour) which I was not able to delete/modify.
If I tried to modify it as "Top Space to SuperView >= 40", it'd be changed to a user constraint( blue colour) and a new purple constraint "Top Space to SuperView = 40" would be created automatically.
I guess this could be the reason:
When I tried to change the constraint to "Top Space to SuperView >= 40", the label's default position is undefined : >= doesn't specify a default position. It specifies only a 'range of positions'. Then I added a new constraint by selecting both the labels together and setting the space between them as a constant.
Now, since the first label had a definite position (vertical space = 15) from the top border and the second label was 5 points below the first one, the second label got a vertical position defined. I was able to delete the purple vertical space constraint.
Now, if I remove the constraint between the two labels, the second one will no more have the defined position and system will automatically create a purple constraint for the label.
When you right-click on the constraint, select "Promote to user constraint". Next time you click on constraint, you will be able to delete it as now it is in the hands of the user/developer.