Unable to satisfy restrictions at the same time - no restrictions

I went through and removed all user restrictions, but after turning the device on, I still get the following error ONLY . I do not know why. Does anyone have any idea?

2013-01-14 21:30:31.363 myApp[35869:c07] 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:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>", "<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>", "<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )> 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. 
+56
ios nslayoutconstraint ipad autoresizingmask
Jan 14 '13 at 21:35
source share
10 answers

Let's look at them one by one.

"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"

This says that the view 0xa330270 ( A ) should be 768 points higher.

"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"

This suggests that the bottom edge 0xa331260 ( B ) should be a space of -1 from the bottom of A , which is the add-on.

"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"

This suggests that the top edge of B should be a gap of 841 points from the top of its supervisor, A.

These three things cannot be true - A cannot be 768 points in height and contain a preview with a top edge of 841 dotted inserts from the top and -1 insertion points from the bottom. Where did you define each of these restrictions?

You did not say which layout you are trying to achieve, but it looks like you might have an autoresist mask in supervision that prevents it from changing its height when you rotate the device. As far as I know, auto-resolution restrictions only appear if you added the views programmatically, because the storyboard or xib is either fully automated or not. If you are not doing something like adding an automatically laid out view (downloaded from a nib?) To another view from a non-autolayout nib file?

+96
Jan 14 '13 at 21:56
source share

thanks to http://useYourLoaf.com for this complete solution:

http://useyourloaf.com/blog/using-identifiers-to-debug-autolayout.html

A quick tip that I found similar to the WWDC 2015 session in Auto Layout that helps with debugging constraint problems

If you used Auto Layout, you'll be familiar with the magazine that Xcode issues when you get something wrong. To create an example, I modified my sample code for the sample stack and added a limit to each of the images to give them a fixed width of 240 (not a good idea, as we will see).

enter image description here

This works in the form of a normal width, such as the iPad, but is too wide for a compact width view, such as the iPhone in portrait. The console log at run time is not readable. Skipping the text of the template, you will get a list of problematic restrictions:

 "<NSLayoutConstraint:0x7fc1ab520360 H:[UIImageView:0x7fc1ab532650(240)]>", "<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>", "<NSLayoutConstraint:0x7fc1ab545cc0 UIView:0x7fc1ab53d870.trailingMargin == UIStackView:0x7fc1ab53dae0.trailing>", "<NSLayoutConstraint:0x7fc1ab545d10 UIStackView:0x7fc1ab53dae0.leading == UIView:0x7fc1ab53d870.leadingMargin>", "<NSLayoutConstraint:0x7fc1ab54e240 'UISV-alignment' UIStackView:0x7fc1ab53dc70.centerX == UIStackView:0x7fc1ab531a10.centerX>", "<NSLayoutConstraint:0x7fc1ab5167c0 'UISV-canvas-connection' UIStackView:0x7fc1ab531a10.leading == UIImageView:0x7fc1ab532650.leading>", "<NSLayoutConstraint:0x7fc1ab54ad80 'UISV-canvas-connection' H:[UIImageView:0x7fc1ab537380]-(0)-| (Names: '|':UIStackView:0x7fc1ab531a10 )>", "<NSLayoutConstraint:0x7fc1ab5397d0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.leading == _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading>", "<NSLayoutConstraint:0x7fc1ab54a4a0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.centerX == UIStackView:0x7fc1ab53dc70.centerX>", "<NSLayoutConstraint:0x7fc1ab54b110 'UISV-spacing' H:[UIImageView:0x7fc1ab532650]-(16)-[UIImageView:0x7fc1ab537380]>", "<NSLayoutConstraint:0x7fc1ab548210 'UISV-spanning-boundary' _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading <= UIStackView:0x7fc1ab531a10.leading>", "<NSLayoutConstraint:0x7fc1ab551690 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fc1ab53d870(375)]>" 

Then the magazine tells you which of the above restrictions he decided to break:

 Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]> 

The output of the magazine uses the automatic layout visual formatting language, but it is difficult to distinguish my limitations from those created by the system. This is especially true for stack views that are designed to create most of the constraints for you. In this trivial example, I know the fixed-width constraints that I just added broke things, but it's hard to see that from a magazine and a more complex view, it's more complicated.

Adding an identifier to a constraint

The log becomes much easier to understand if you add an identifier for each constraint ( NSLayoutConstraint has an identifier property with iOS 7). In Interface Builder, find the restriction and add the identifier in the attribute inspector (I use $ as a prefix / suffix to highlight them in the log):

enter image description here

Update August 18, 2015. As indicated in the comments, the identifier can only be edited in Interface Builder starting with Xcode 7. It does not appear in Xcode 6.4.

If you add a restriction to the code:

 constraint.identifier = "$HeartImageFixedWidth$" 

This is harder if you use a visual format language that uses constraint arrays. For example, consider a piece of Swift code to create a fixed-width constraint to represent an image with a heart:

 let heartWidth = NSLayoutConstraint.constraintsWithVisualFormat("[heart(240)]", options:[], metrics:nil, views:viewsDictionary) 

Since heartWidth is an array of type [NSLayoutConstraint], identifier is a bit more work:

 for constraint in heartWidth { constraint.identifier = "$HeartImageFixedWidth$" } heartImage.addConstraints(heartWidth) 

With the identifiers set for my restrictions, it is now much easier to find them in the log file (see the first four lines):

 "<NSLayoutConstraint:0x7f92a305aeb0 '$ContainerStackViewLeading$' UIStackView:0x7f92a3053220.leading == UIView:0x7f92a3052fb0.leadingMargin + 32>", "<NSLayoutConstraint:0x7f92a305b340 '$ContainerStackViewTrailing$' UIView:0x7f92a3052fb0.trailingMargin == UIStackView:0x7f92a3053220.trailing + 32>", "<NSLayoutConstraint:0x7f92a301cf20 '$HeartImageFixedWidth$' H:[UIImageView:0x7f92a3047ef0(240)]>", "<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>", "<NSLayoutConstraint:0x7f92a3060cc0 'UISV-alignment' UIStackView:0x7f92a30533b0.centerX == UIStackView:0x7f92a30472b0.centerX>", "<NSLayoutConstraint:0x7f92a301c590 'UISV-canvas-connection' UIStackView:0x7f92a30472b0.leading == UIImageView:0x7f92a3047ef0.leading>", "<NSLayoutConstraint:0x7f92a305f680 'UISV-canvas-connection' H:[UIImageView:0x7f92a304d190]-(0)-| (Names: '|':UIStackView:0x7f92a30472b0 )>", "<NSLayoutConstraint:0x7f92a3064190 'UISV-canvas-connection' UIStackView:0x7f92a3053220.leading == _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading>", "<NSLayoutConstraint:0x7f92a30415d0 'UISV-canvas-connection' UIStackView:0x7f92a3053220.centerX == UIStackView:0x7f92a30533b0.centerX>", "<NSLayoutConstraint:0x7f92a305fa10 'UISV-spacing' H:[UIImageView:0x7f92a3047ef0]-(16)-[UIImageView:0x7f92a304d190]>", "<NSLayoutConstraint:0x7f92a30508c0 'UISV-spanning-boundary' _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading <= UIStackView:0x7f92a30472b0.leading>", "<NSLayoutConstraint:0x7f92a3063240 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f92a3052fb0(375)]>" 

In addition, it is much clearer which of the restrictions that the system has chosen to split:

 Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]> 

Adding identifiers to restrictions is not without effort, but it may pay off the next time you have to sort the debug log of a complex layout.

additional literature

+14
Oct 11 '15 at 17:05
source share

I suppose this is not a common mistake, but I solved it a bit by a layman. I have received cryptic messages like the ones above. To understand this, I created dummy view classes and attached it to the views in my storyboard. For example, if I had a UIView, I created the AddressView class and attached it to this view in the bulletin board. It was a little time, but it worked for me. After that, instead of identifier objects, I got class names that helped me from scratch in the views that caused the problem very easily. Now my error message is being read,

 2013-07-02 04:16:20.434 Myproject [2908:c07] 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:0x9edeae0 V:|-(0)-[AddressView:0x143ee020] (Names: '|':MainView:0x129eb6a0 )>", "<NSAutoresizingMaskLayoutConstraint:0x11e998c0 h=--& v=--& V:[MainView:0x129eb6a0(704)]>", "<NSLayoutConstraint:0x156720b0 V:[AddressView:0x143ee020]-(896)-| (Names: '|':MainView:0x129eb6a0 )>" ) 

Here you can see that the names of my views, MainView and Address view, are causing the problem.

To solve this problem, I simply moved my view (in this case Address view) and moved it back. I think the problem started when I used a combination of the new automatic Layour in Xcode 4.5 and old skills or manually positioned the views.

In any case, I’m not sure that it was more luck than zeal, but nevertheless, it may be a different way of debugging. Maybe this helps someone!

+9
Jul 02 '13 at 2:30
source share

Its worth knowing the basics and understanding what Apple / Xcode is trying to tell you through magazines.

 H = Horizontal constraint(for leading and Trailing) V = Vertical constraint(top and bottom edge) h = height w = width TopEdge -> V:|-(points)-[VIEW:memoryAddress] BottomEdge -> V:[VIEW:memoryAddress]-(points)-| Leading -> H:|-(points)-[VIEW:memoryAddress] Trailing -> H:[VIEW:memoryAddress] -(points)-| height -> h= --& v=--& V:[VIEW:memoryAddress((points)] width -> VIEW:memoryAddress.width == points between -> H:[VIEW 1]-(51)-[VIEW 2] 

Once you understand this, reading your specific error is pretty easy.

+7
Jul 10 '17 at 9:50
source share

YourConstraintView.translatesAutoresizingMaskIntoConstraints = NO;

Did it for me.

+4
Apr 12 '16 at 7:34
source share

I fixed this problem by removing all the translatesAutoresizingMaskIntoConstraints properties from the xib file (Open xib as source).

+3
May 27 '14 at 4:28
source share

One note. You get this error in the logs if you are testing using a personal connection to the access point, and the hotspot status bar is at the top. It resets restrictions.

Hope this helps someone ... drove me crazy.

+2
Jan 08 '16 at 23:36
source share

For me, this error was revealed when I gave tableView.estimatedRowHeight = UITableViewAutomaticDimension

It should have been tableView.estimatedRowHeight = "Some hardcoded value"

0
Mar 26 '18 at 22:32
source share

I had this problem and it took me 2 days to figure out the source of the problem ....

If you open the storyboard programmatically in your code, just make sure you do it like this:

 UIStoryboard *story = [UIStoryboard storyboardWithName:@"MovieMaker" bundle:nil]; UIViewController *vc = [story instantiateInitialViewController]; //this causes layout to break [self presentViewController:vc animated:YES completion:nil]; [self showViewController:vc sender:nil]; 

I used a commented out line (using presentViewController) and an orientation error occurred leading to constraint conflicts that were not my constraints ... when switching to showViewController all constraint conflicts disappeared and the orientation works ...... I don’t know, why he works with the show and is not present ... still thinks that it is ... Aliens ...)

0
Apr 30 '18 at 22:28
source share

This issue of the generated message "Unable to satisfy constraints at the same time" in the debug console also occurs in Xcode 9.4.
In my particular case, on the iPad simulator a message will be generated:
1) Only when placing focus on a specific UITextField.
2) Even with all visible limitations.
2) Even with all the viewing restrictions, "Reset to recommended restrictions."

However, when the soft keyboard was turned on for display, a message will not be generated. Therefore, how much time should I spend on this problem, which in my case is generated only when the software keyboard is turned off.

0
Jun 20 '18 at 2:20
source share



All Articles