Autolayout Constraint Error - ios

I have a problem with autolayout contraints on my iPad project, when I rotate my device I have this error :
2013-06-03 13:16:24.969 PDFViewer[7534:907] 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:0x1f5525e0 H:[UIScrollView:0x1f551910]-(970)-| (Names: '|':UIView:0x1f547740 )>",
"<NSLayoutConstraint:0x1f5525a0 H:|-(0)-[UIScrollView:0x1f551910] (Names: '|':UIView:0x1f547740 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1f562520 h=--- v=--- H:[UIWindow:0x1f543890(768)]>",
"<NSAutoresizingMaskLayoutConstraint:0x1f560af0 h=-&- v=-&- UIView:0x1f547740.width == UIWindow:0x1f543890.width>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1f5525e0 H:[UIScrollView:0x1f551910]-(970)-| (Names: '|':UIView:0x1f547740 )>
Ok, some constraints are contentious but I don't set any constraint by myself, they are all set automatically in Interface Builder and I can't remove them. What I want is pretty simple, a scrollview, with fixed width and 100% height, and a collection view, with remaining width and 100% height.
Autolayout makes me crazy, any idea ?
Edit : Here are my constraints defined in IB

Error was caused by an automatic constraint, more precisely this one :
"<NSLayoutConstraint:0x1f5525e0 H:[UIScrollView:0x1f551910]-(970)-| (Names: '|':UIView:0x1f547740 )>",
As it is added by IB you can't delete it, so for ignoring it I have set the priority to 1.

Related

iOS - auto layout rotation not working as expected

I have app with enabled rotation for iPad (iPhone version is rotation-free). In my design, within storyboard, I have this hierarchy: UIView - UIScrollView - UIView. All "views" are set to have full width of the screen. Second UIView has class set to MyView, which is a class with an external xib file. Storyboard and xib are both created in a portrait mode.
Now for the problem.
If I run the app in the landscape mode, all is loaded OK. If I rotate
app after that, all is OK.
If I run the app in the portrait mode, the design "breaks". The entire content is thiner (so there is about 100+ px gap between the end of MyView and the end of the screen). If I rotate app, the design remains broken but correctly "enlarged". The gap is still of the same size. During the first launch, I got the following error in debugger:
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:0x1545b7800 h=-&- v=-&- UIView:0x1546a8cb0.width == ScrollableContentView:0x154575da0.width - 232>",
"<NSLayoutConstraint:0x15458dd80 H:[UIActivityIndicatorView:0x1546afa60]-(370)-| (Names: '|':UIView:0x1546ab840 )>",
"<NSLayoutConstraint:0x15458ddd0 H:|-(361)-[UIActivityIndicatorView:0x1546afa60] (Names: '|':UIView:0x1546ab840 )>",
"<NSLayoutConstraint:0x1546c7080 H:[UIView:0x1546ab840]-(0)-| (Names: '|':UIView:0x1546a8cb0 )>",
"<NSLayoutConstraint:0x1546c7120 H:|-(0)-[UIView:0x1546ab840] (Names: '|':UIView:0x1546a8cb0 )>",
"<NSLayoutConstraint:0x154579710 H:|-(0)-[ScrollableContentView:0x154575da0] (Names: '|':UIScrollView:0x15504c000 )>",
"<NSLayoutConstraint:0x154686ef0 UIScrollView:0x15504c000.centerX == ScrollableContentView:0x154575da0.centerX>",
"<NSLayoutConstraint:0x154697cc0 H:[UIScrollView:0x15504c000]-(0)-| (Names: '|':UIView:0x154547b80 )>",
"<NSLayoutConstraint:0x154697d10 H:|-(0)-[UIScrollView:0x15504c000] (Names: '|':UIView:0x154547b80 )>",
"<NSLayoutConstraint:0x15463b8c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x154547b80(768)]>"
)
Will attempt to recover by breaking constraint
No matter what I do, I am unable to remove this problem. Even If I deleted almost every constraint I have still the same issue.
You should look if you don't have any auto layout warnings in your storyboard or xib file (yellow/red dot beside your controller name in document outline).
If you don't have any, do you set your constraints when adding your xib view ?
Have you think about content hugging priority or content compression resistance priority ?

Creating a "self-sizing" UITableViewHeaderView

OK, a really simple version of this that breaks...
Create a UIView in a nib.
Add an imageView to it. Give the image view a constraint for an Aspect Ratio of 1:1.
Now add constraints from the image view to the edge of the view. (0 size to pin it to the edges).
Now add the view as a UITableView tableHeaderView.
When you run the application on different devices it will break the constraints and remove the aspect ratio constraint. I don't want this, I want it to change the height of the view to be equal to the width.
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. (
"<NSLayoutConstraint:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>",
"<NSLayoutConstraint:0x7fad04703630 H:[UIImageView:0x7fad047209b0]-(0)-| (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703680 V:|-(0)-[UIImageView:0x7fad047209b0] (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703740 V:[UIImageView:0x7fad047209b0]-(0)-| (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703790 H:|-(0)-[UIImageView:0x7fad047209b0] (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad0429bcf0 'UIView-Encapsulated-Layout-Height' V:[VenueHeaderView:0x7fad047204c0(300)]>",
"<NSLayoutConstraint:0x7fad0429bca0 'UIView-Encapsulated-Layout-Width' H:[VenueHeaderView:0x7fad047204c0(375)]>" )
Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>
It seems that there are constraints UIView-Encapsulated-Layout-Height being added to the superview. But these are added with the wrong value. It should recalculate these based on the internal constraints of the header view.

Prevent Interface Builder from auto creating Constraints?

I created a demo project here. I have a view where I created a ScrollView in a .xib file. In interface builder I did not set any constraints. In my viewDidLoad method I set constraints with SnapKit:
scrollView.snp_makeConstraints { (make) -> Void in
make.edges.equalTo(self.view)
}
When I run the code I get the following console output:
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)
(
"<NSIBPrototypingLayoutConstraint:0x7b74e280 'IB auto generated at build time for view with fixed frame' V:|-(1)-[UIScrollView:0x7b74c430] (Names: '|':UIView:0x7b74dd10 )>",
"<<DeviceImagesTest.LayoutConstraint:0x7baa2760> <UIScrollView:0x7b6608d0>.top == <UIView:0x7b64d800>.top>"
)
Will attempt to recover by breaking constraint
<NSIBPrototypingLayoutConstraint:0x7b74e280 'IB auto generated at build time for view with fixed frame' V:|-(1)-[UIScrollView:0x7b74c430] (Names: '|':UIView:0x7b74dd10 )>
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.
2015-05-29 18:37:14.368 DeviceImagesTest[36462:607] 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)
(
"<NSIBPrototypingLayoutConstraint:0x7b74e080 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIScrollView:0x7b74c430](LTR) (Names: '|':UIView:0x7b74dd10 )>",
"<NSIBPrototypingLayoutConstraint:0x7b74e330 'IB auto generated at build time for view with fixed frame' H:[UIScrollView:0x7b74c430(600)]>",
"<<DeviceImagesTest.LayoutConstraint:0x7baa7170> <UIScrollView:0x7baa7b30>.right == <UIView:0x7baa79a0>.right>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa4800 h=-&- v=-&- UIView:0x7b74dd10.width == UIViewControllerWrapperView:0x7ba9f060.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa5180 h=-&- v=-&- UIViewControllerWrapperView:0x7ba9f060.width == UINavigationTransitionView:0x7bc769b0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa58e0 h=-&- v=-&- UINavigationTransitionView:0x7bc769b0.width == UILayoutContainerView:0x7bc75140.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa61a0 h=-&- v=-&- UILayoutContainerView:0x7bc75140.width == UIWindow:0x7bc71870.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa69a0 h=--- v=--- H:[UIWindow:0x7bc71870(320)]>"
)
Will attempt to recover by breaking constraint
<<DeviceImagesTest.LayoutConstraint:0x7baa95b0> <UIScrollView:0x7baa9610>.right == <UIView:0x7baa96b0>.right>
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.
2015-05-29 18:37:14.496 DeviceImagesTest[36462:607] 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)
(
"<NSIBPrototypingLayoutConstraint:0x7b74e360 'IB auto generated at build time for view with fixed frame' V:[UIScrollView:0x7b74c430(600)]>",
"<<DeviceImagesTest.LayoutConstraint:0x7bc77e40> <UIScrollView:0x7bc7f6a0>.top == <UIView:0x7bc52180>.top>",
"<<DeviceImagesTest.LayoutConstraint:0x7bc49420> <UIScrollView:0x7bc74b00>.bottom == <UIView:0x7bc7b970>.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa4960 h=-&- v=-&- UIView:0x7b74dd10.height == UIViewControllerWrapperView:0x7ba9f060.height>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa51e0 h=-&- v=-&- UIViewControllerWrapperView:0x7ba9f060.height == UINavigationTransitionView:0x7bc769b0.height>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa5940 h=-&- v=-&- UINavigationTransitionView:0x7bc769b0.height == UILayoutContainerView:0x7bc75140.height>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa6200 h=-&- v=-&- UILayoutContainerView:0x7bc75140.height == UIWindow:0x7bc71870.height>",
"<NSAutoresizingMaskLayoutConstraint:0x7baa69d0 h=--- v=--- V:[UIWindow:0x7bc71870(568)]>"
)
Will attempt to recover by breaking constraint
<<DeviceImagesTest.LayoutConstraint:0x7bc84790> <UIScrollView:0x7bc848b0>.bottom == <UIView:0x7bc84860>.bottom>
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.
It seems that Interface Builder is generating Constraints for me even if I did not set any. This leads to a conflict with my constraints I set in code. I also set setTranslatesAutoresizingMasks(false).
How can I prevent Interface Builder from auto generating constraints?
If you are confused about the NSAutoresizingMaskLayoutConstraints in that list, it might be because you haven't called setTranslatesAutoresizingMasksIntoContraints(false) on that view. (although, I was under the impression that SnapKit does that for you).
If you are confused about the NSIBPrototypingLayoutConstraint, that's an auto-generated constraint by Interface Builder. To get rid of it, add some Top, Bottom, Leading and Trailing constraints in Interface Builder and set them to be removed at build time. For more details about that, have a look at http://travisjeffery.com/b/2013/11/preventing-ib-auto-generated-at-build-time-for-view-with-fixed-frame/
UPDATE: url was changed to http://travisjeffery.com/b/2013/11/preventing-ib-auto-generated-at-build-time-for-view-with-fixed-frame-when-using-auto-layout/
How can I prevent Interface Builder from auto generating constraints?
Simplest way: select the nib or storyboard in the project navigator, go to the File inspector, and uncheck "Use Auto Layout".

How can I detect the views whose constraints are being unsatisfied?

I am constantly getting this error:
2014-09-13 23:56:19.904 Parrot[245: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:0x14641170 H:[UILabel:0x14641060(200)]>",
"<NSLayoutConstraint:0x14643670 H:[UILabel:0x14641060]-(60)-| (Names: '|':UIView:0x14641590 )>",
"<NSLayoutConstraint:0x146436a0 H:|-(60)-[UILabel:0x14641060] (Names: '|':UIView:0x14641590 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1464bc70 h=--& v=--& H:[UIView:0x14641590(480)]>"
)
How can I detect the views whose constraints are being unsatisfied?
[UILabel:0x14641060]
It's in error message.
It seems this UILabel has three constraints. Remove any one of these you can satisfy the constraints

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?

Resources