iOS "Unable to simultaneously satisfy constraints" - ios

I will use the following notation to explain the invovled views:
{V} – the ‘superview’, i.e. the main view of the root controller
{Q} – a rectangle at the center of the screen used as a quiz
{W} – a white bar above {Q}
I’m getting the following output when running on iPad-Air2 simulator:
2016-11-03 08:09:07.700117 MyApp[16645:6976134] [LayoutConstraints] 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:0x60000009d600 h=--& v=--& QuizButtons:0x7fcb8e521830.width == 717 (active)>",
"<NSLayoutConstraint:0x608000281fe0 H:|-(0)-[ImgWhiteBar:0x7fcb8e525020] (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x608000282210 ImgWhiteBar:0x7fcb8e525020.width == 1.07143*QuizButtons:0x7fcb8e521830.width (active)>",
"<NSLayoutConstraint:0x60000009b9e0 'UIView-Encapsulated-Layout-Width' ViewTestVC:0x7fcb8e639b30.width == 768 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
My interpretation to logged constraints is this:
{Q}: default <h=--& v=--&>, width =717
Horiz: {V.lead} -0- {W}
Horiz: {W} -0- {V.trail}
{W.width} = 1.07 * {Q.width}
{V.width} = 768
Or maybe a bit simpler
{Q.width} must be 717
{W.width} must be 768.21531
{W} must touch both sides of {V}
{V.width} = 768
Questions:
Is my interpretation correct?
What is the problem here? It is due to the inaccuracy of the 768.2 vs 768? If yes, who told Xcode to use 717? I told {Q.width} to be {W.width}/[14:15]
Will appreciate any help here!
EDIT
Here are three of the constraints:

The list of the conflicting constraints includes h=--& v=--& which is the default non-autolayout form.
I was trying to get the initial size and position using auto-layout, and then tried to turn auto-layout off by setting translatesAutoresizingMaskIntoConstraints=YES. I got an answer in the Apple developer forum saying that in such case I need to remove all constraints for the view, possibly by removing from the superview and adding back.
TIP
While investigating this bug, I have found a way to make the constraints-conflict log much easier to understand. The problem is that the views appear anonymous, specifying only the class but not the name.
To make your views identifiable, open one of your .m files and add a new class for each view you want to identify, like this:
#interface ImgWhiteBar: UIImageView
#end
#implementation ImgWhiteBar
#end
#interface Spacer1: UIView
#end
#implementation Spacer1
#end
After that, in InterfaceBuilder, select each view, and then at the "Identity Inspector" on the right modify the generic class (UIVIew, UIImageView etc.) into one of the classes you just created.
Now run again, and Abracadabra - all views are now identified with their custom classes, allowing you to understand what is going on there.
Have fun debugging constraints!

Related

Xcode Swift: Why is it breaking my Constraints?

I'm just learning Swift with the Start Developing iOS Apps (Swift) Tutorial. I'm creating this custom Rating Control but every time i run the App is sends following Error:
2017-08-09 15:49:41.894597+0200 FoodTracker[5051:2273797] [LayoutConstraints] 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:0x17409af90 UIButton:0x100c12d90.width == 44 (active)>",
"<NSLayoutConstraint:0x17009c160 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.leading == UIButton:0x100c12d90.leading (active)>",
"<NSLayoutConstraint:0x17009c200 'UISV-canvas-connection' H:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400 )>",
"<NSLayoutConstraint:0x17009bee0 'UIView-Encapsulated-Layout-Width' FoodTracker.RatingControl:0x100c02400.width == 343 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17409af90 UIButton:0x100c12d90.width == 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-08-09 15:49:41.895770+0200 FoodTracker[5051:2273797] [LayoutConstraints] 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:0x17409af40 UIButton:0x100c12d90.height == 44 (active)>",
"<NSLayoutConstraint:0x17009c250 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.top == UIButton:0x100c12d90.top (active)>",
"<NSLayoutConstraint:0x17009c340 'UISV-canvas-connection' V:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400 )>",
"<NSLayoutConstraint:0x17009bf30 'UIView-Encapsulated-Layout-Height' FoodTracker.RatingControl:0x100c02400.height == 50 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17409af40 UIButton:0x100c12d90.height == 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
I set the constraints for Button width == 44 and for Button height == 44, but none of the other constraints. I did everything as described in the Tutorial and have no clue why it doesn't work. I Checked all Constraints i can find but i'm not sure if it were all as I'm not very experienced with Xcode. Do anyone have a clue how to solve the Problem?
This is how it should look like: But this is how it looks: (Only The Red Area is important)
I also faced similar issue. The solution is simple, as shown, move (drag and drop) horizontal stack view under the vertical stack view as shown.
Based on the error message, I think you have embedded the button inside a UIStackView. The stack view has incorrect constraints, or no constraints at all and is using the autoresizing mask. The stack view is being given a size of 343x50 and is forcing the button to match.
Looks like you have a UIStackView. Remove the UIButton out of the UIStackView and set that UIButton's top constraint the same spacing you defined in your UIStackView and set the UIButton's align leading edge to the UiStackView and you're good
I have found reason and solution.
Horizontal Stack View - filling whole own internal space by vertical and horizontal. It's mean - Horizontal Stack View will set height and wight for internal items to Fill all available space.
Only way to remove such warning which i found - is set width/height of Horizontal Stack View to fit perfectly with/height of all internal elements: 252x44

AVPlayerViewController - No Auto Layout - Unable to simultaneously satisfy constraints.

In my project I have created a ViewController and created a class as "AVPlayerViewController" in order to show videos.
The code works and I am able to see the videos however, I get some constraints warnings in the console.
My project is working without AutoLayout and I use AutoResizing. I have tried the code:
self.view.translatesAutoresizingMaskIntoConstraints = false
but the warnings are not going away and the controls of the video player move to the top of the screen .
There warnings are:
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:0x1475c4540 h=-&- v=-&- _UIBackdropContentView:0x147443880.width == _UIBackdropView:0x147436a30.width>",
"<NSLayoutConstraint:0x1475b38f0 H:|-(0)-[_UIBackdropView:0x147436a30] (Names: '|':UIView:0x1474368d0 )>",
"<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-| (Names: '|':UIView:0x1474368d0 )>",
"<NSLayoutConstraint:0x1475b3650 H:|-(0)-[UIView:0x1474368d0] (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
"<NSLayoutConstraint:0x1475b36d0 H:[UIView:0x1474368d0]-(0)-| (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
"<NSLayoutConstraint:0x1475c7670 H:|-(15)-[UIView:0x1474435c0](LTR) (Names: '|':_UIBackdropContentView:0x147443880 )>",
"<NSLayoutConstraint:0x1475c54d0 UIView:0x147443b40.right == _UIBackdropContentView:0x147443880.right>",
"<NSLayoutConstraint:0x1475c7a40 UIView:0x1474435c0.right == UIView:0x147443b40.left - 10>",
"<NSLayoutConstraint:0x1475c4da0 'UIView-Encapsulated-Layout-Width' H:[AVAlphaUpdatingView:0x14744db30(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-| (Names: '|':UIView:0x1474368d0 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Any Idea what to do?
As per this answer Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard the solution seems to be to set showsPlayBackControls off on the PlayerController and then add it to the view.
Once you have an AVPlayer item, you can show the player controls again (assuming you need them).
I suspect that a valid AVPlayer item is needed in order for the player control constraints to be properly satisfied.
I had this exact same issue and managed to fix it by making this change. Good luck!
Strangely enough, what you do is create a second view under your main view, and then add your player view as a subview to that.
This very problem took me an entire day to solve a month ago, and that's how it got solved. You must remove any code that auto resizes constraints, though.
If you are programmatically creating the view for your view controller, add the AVPlayerViewController as a child view controller and its view as a subview in loadView() method instead of viewDidLoad(). No need to hide playback controls.

Correctly define constraint for UITableViewCell resizing

i'm currently facing this problem, i need to define a dynamic height UITableViewCell.
The red lines correspond to resizable views (will grow vertically), the blue label have 3 constraints: two for each immediate red views above (>= 8), one more with 170 and lower priority to superview.
The green one has a bottom constraint to the superview (5)
When i try to run my code, it gives me 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:0x19d65bb0 V:[UIView:0x19d9a9a0(5)]>",
"<NSLayoutConstraint:0x19d667d0 V:[UILabel:0x19de4180(19)]>",
"<NSLayoutConstraint:0x19d5ba70 V:[UILabel:0x19d61870(19)]>",
"<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>",
"<NSLayoutConstraint:0x19d35d30 V:[UIView:0x19d36130(0)]>",
"<NSLayoutConstraint:0x19e7b310 V:|-(5)-[UILabel:0x19d6b520] (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSLayoutConstraint:0x17d0b060 V:[UILabel:0x19d6b520]-(5)-[UIView:0x19d9a9a0]>",
"<NSLayoutConstraint:0x17d0a480 V:[UIView:0x19d9a9a0]-(8)-[UILabel:0x19de4180]>",
"<NSLayoutConstraint:0x17d0c920 V:[UILabel:0x19de4180]-(8)-[UILabel:0x19d61870]>",
"<NSLayoutConstraint:0x17d0a100 V:[UILabel:0x19d61870]-(8)-[UIView:0x19d839e0]>",
"<NSLayoutConstraint:0x17d11ad0 V:[UIView:0x19d839e0]-(8)-[UILabel:0x19d36e80]>",
"<NSLayoutConstraint:0x19e742a0 V:[UILabel:0x19d36e80]-(8)-[UILabel:0x19d36770]>",
"<NSLayoutConstraint:0x19ed84a0 V:[UILabel:0x19d36770]-(8)-[UIView:0x19d36130]>",
"<NSLayoutConstraint:0x19e76410 V:[UIView:0x19d36130]-(>=8)-[UILabel:0x19d35560]>",
"<NSLayoutConstraint:0x19ed8af0 V:[UILabel:0x19d35560]-(8)-[UITextView:0x1832ba00]>",
"<NSLayoutConstraint:0x19e7abf0 V:[UITextView:0x1832ba00]-(8)-[UILabel:0x19e7d890]>",
"<NSLayoutConstraint:0x19e83d90 V:[UILabel:0x19e7d890]-(8)-[UITextView:0x18a95e00]>",
"<NSLayoutConstraint:0x19e7b520 V:[UITextView:0x18a95e00]-(5)-| (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSAutoresizingMaskLayoutConstraint:0x19d46fc0 h=--& v=--& V:[UITableViewCellContentView:0x19d97580(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>
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.
So, the question is:
What is the correct way of achieving this???
Are u using storyboard, if yes, simple go to Editor->Resolve Auto Layout Issues->Clear All Constraints In ........ Controller, and then Add Missing Constraints In ...... Controller
It will help you fix the problem of breaking contrainsts between view

Unable to simultaneously satisfy constraints - No constraints in place

I have gone through and removed every single user constraint yet I am still getting the following error ONLY after I rotate the device. I have absolutely no clue why though. Does anyone have any ideas?
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.
Let's look at these one by one.
"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"
This is saying view 0xa330270 (A) must be 768 points high.
"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"
This is saying view 0xa331260 (B)'s bottom edge must be a gap of -1 from the bottom of A, which is it's superview.
"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"
This is saying that B's top edge must be a gap of 841 points from the top of its superview, A.
These three things can't all be true - A can't be 768 points high, and contain a subview with a top edge 841 points inset from the top and -1 points inset from the bottom. Where have you defined each of these constraints?
You haven't said what layout you are trying to achieve, but it looks like you might have an autoresizing mask on the superview that is preventing it changing in height when you rotate the device. As far as I know the autoresizing constraints only appear if you have added views programmatically, since a storyboard or xib is either all-autolayout, or not. Unless you are doing something like adding an auto laid out view (loaded from a nib?) to another view from a non-autolayout nib?
Its worth knowing the basics, and understand what Apple/Xcode is trying to tell you through the logs
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
thanks to http://useYourLoaf.com for this complete solution:
http://useyourloaf.com/blog/using-identifiers-to-debug-autolayout.html
A quick tip I found buried in a WWDC 2015 session on Auto Layout that helps when debugging problems with constraints
If you have used Auto Layout you will be familiar with the log that Xcode spits out when you get something wrong. To create an example I modified my Stack View sample code and added a constraint to each of the images to give them a fixed width of 240 (not a good idea as we will see).
That works in regular width views such as the iPad but is too wide for a compact width view such as the iPhone in portrait. The console log at runtime is not fun to read. Skipping the boilerplate text you get a list of the problematic constraints:
"<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)]>"
The log then tells you which of the above constraints it has decided to break:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>
The log output uses the auto layout visual format language but it is hard to pick out my constraints from those created by the system. This is especially the case with stack views which are by design intended 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 is hard to see that from the log and the more complex the view the harder it gets.
Adding an Identifier to a Constraint
The log gets a lot easier to understand if you add an identifier to each constraint (NSLayoutConstraint has had an identifier property since iOS 7). In Interface Builder find the constraint and add the identifier in the Attributes inspector (I am using $ as a prefix/suffix to make them stand out in the log):
Update 18-August-2015: As pointed out in the comments the identifier can only be edited in Interface Builder starting with Xcode 7. It is not visible in Xcode 6.4.
If adding the constraint in code:
constraint.identifier = "$HeartImageFixedWidth$"
It is trickier if you are using the visual format language which uses arrays of constraints. For example, consider the Swift code fragment to create a fixed width constraint for the heart image view:
let heartWidth = NSLayoutConstraint.constraintsWithVisualFormat("[heart(240)]",
options:[], metrics:nil, views:viewsDictionary)
Since heartWidth is an array of type [NSLayoutConstraint] setting the identifier is a little more work:
for constraint in heartWidth {
constraint.identifier = "$HeartImageFixedWidth$"
}
heartImage.addConstraints(heartWidth)
With identifies set for my constraints 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)]>"
It also much clearer which of the constraints the system has chosen to break:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>
Adding identifiers to constraints is not without effort but it can pay off the next time you have to sort through the debug log of a complex layout.
Further Reading
WWDC 2015 Session 219 Mysteries of Auto Layout, Part 2
I guess this is not a common error, but I solved it somewhat in a layman way. I was getting cryptic messages like the one above. To make sense of it, I created dummy view classes and attached it to the views in my storyboard. For example, if I had a UIView, I created a class called AddressView and attached it to this view in story board. Its a bit time consuming, but it worked for me. After that instead of object-ids, I got class names which helped me zero in on the views that were causing the issue very easily. My error message now 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, the names of my views MainView and Address view are causing the issue.
To resolve it, I just moved my subview (in this case Address view) and repositioned it back. I think the issue began as I was using a mix of new Automatic Layour in Xcode 4.5 and old skills or manually positioning the views.
Anyways, not sure if it was more luck than diligence, but nevertheless this could be a different way of debugging. Maybe this helps someone!
YourConstraintView.translatesAutoresizingMaskIntoConstraints = NO;
Did it for me.
I've fixed this problem be deleting all translatesAutoresizingMaskIntoConstraints properties from xib file (Open xib as a source code).
One note. You get this error in logs if you are testing using a personal hotspot connection, and the hotspot status bar is at the top. It throws off the constraints.
Hope this helps someone.. was driving me nuts.
For me this error was spitted when I gave tableView.estimatedRowHeight = UITableViewAutomaticDimension
This should have been tableView.estimatedRowHeight = "Some hardcoded value"
I had this problem and took me 2 days to figure out the source of the problem....
If you open a storyboard programmatically in you 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 was using the commented line (using presentViewController) and the orientation bug has happening throwing constraints conflicts that weren't my constraints... changing to showViewController all constraints conflicts were gone and orientation works...... (I don't really know why it works with show and not present... still thinking it's... ALIENS...)
This issue of the generated message "Unable to simultaneously satisfy contraints" in the debug console, is also experienced in XCode 9.4.
In my particular instance on the iPad simulator, the message would generate:
1) Only when placing the focus on a particular UITextField.
2) Even with all view contraints removed.
2) Even with all view contraints "Reset to Suggested Contraints".
However, when the software keyboard was toggled on to display, the message would not be generated.
Therefore, how much time should I spend on this issue, that in my instance is only generated when the software keyboard is toggled off.
this line solved my problem when logs like above in uitableviewCell
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension > CellHeight.rowHeight44 ? UITableView.automaticDimension : CellHeight.rowHeight44
}

Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint

Below is the error message I receive in the debug area. It runs fine and nothing is wrong except that I receive this error. Would this prevent apple accepting the app? How do I fix it?
2012-07-26 01:58:18.621 Rolo[33597:11303] 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:0x887d630 h=--& v=--& V:[UIButtonLabel:0x886ed80(19)]>",
"<NSAutoresizingMaskLayoutConstraint:0x887d5f0 h=--& v=--& UIButtonLabel:0x886ed80.midY == + 37.5>",
"<NSAutoresizingMaskLayoutConstraint:0x887b4b0 h=--& v=--& V:[UIButtonLabel:0x72bb9b0(19)]>",
"<NSAutoresizingMaskLayoutConstraint:0x887b470 h=--& v=--& UIButtonLabel:0x72bb9b0.midY == - 0.5>",
"<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>",
"<NSLayoutConstraint:0x72c2430 UILabel:0x72bfad0.top == UILabel:0x72bf7c0.top>",
"<NSLayoutConstraint:0x72c2370 UILabel:0x72c0270.top == UILabel:0x72bfad0.top>",
"<NSLayoutConstraint:0x72c22b0 V:[UILabel:0x72bf7c0]-(NSSpace(8))-[UIButton:0x886efe0]>",
"<NSLayoutConstraint:0x72c15b0 V:[UILabel:0x72c0270]-(NSSpace(8))-[UIRoundedRectButton:0x72bbc10]>",
"<NSLayoutConstraint:0x72c1570 UIRoundedRectButton:0x72bbc10.baseline == UIRoundedRectButton:0x7571170.baseline>",
"<NSLayoutConstraint:0x72c21f0 UIRoundedRectButton:0x7571170.top == UIButton:0x886efe0.top>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>
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.
I would recommend to debug and find which constraint is "the one you don't want". Suppose you have following issue:
Always the problem is how to find following Constraints and Views.
There are two solutions how to do this:
DEBUG VIEW HIERARCHY (Do not recommend this way)
Since you know where to find unexpected constraints (PBOUserWorkDayHeaderView) there is a way to do this fairly well. Let's find UIView and NSLayoutConstraint in red rectangles. Since we know their id in memory it is quite easy.
Stop app using Debug View Hierarchy:
Find the proper UIView:
The next is to find NSLayoutConstraint we care about:
As you can see, the memory pointers are the same. So we know what is going on now. Additionally you can find NSLayoutConstraint in view hierarchy. Since it is selected in View, it selected in Navigator also.
If you need you may also print it on console using address pointer:
(lldb) po 0x17dce920
<UIView: 0x17dce920; frame = (10 30; 300 24.5); autoresize = RM+BM; layer = <CALayer: 0x17dce9b0>>
You can do the same for every constraint the debugger will point to you:-) Now you decide what to do with this.
PRINT IT BETTER (I really recommend this way, this is of Xcode 7)
set unique identifier for every constraint in your view:
create simple extension for NSLayoutConstraint:
SWIFT:
extension NSLayoutConstraint {
override public var description: String {
let id = identifier ?? ""
return "id: \(id), constant: \(constant)" //you may print whatever you want here
}
}
OBJECTIVE-C
#interface NSLayoutConstraint (Description)
#end
#implementation NSLayoutConstraint (Description)
-(NSString *)description {
return [NSString stringWithFormat:#"id: %#, constant: %f", self.identifier, self.constant];
}
#end
build it once again, and now you have more readable output for you:
once you got your id you can simple tap it in your Find Navigator:
and quickly find it:
HOW TO SIMPLE FIX THAT CASE?
try to change priority to 999 for broken constraint.
The problem you're having is the NSAutoresizingMaskLayoutConstraints should not be in there. This is the old system of springs and struts. To get rid of it, run this method on each view that you're wanting to constrain:
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
Be careful, that you do not use more than one constraint in the same direction and type.
For example:
Vertical constraint for trailing = 15 and another one is >= 10.
Sometimes, Xcode creates some constraints you don't notice.
You have to get rid of redundant constraints and the log warning will surely disappear.
Additionaly, you can read and detect some certain reasons, directly from the log:
NSLayoutConstraint:0xa338390 V:|-(15)-[UILabel:0xa331260] (Names:
'|':UILabel:0xa330270 )>
This we can read as problem in UILabel constraint, it is leading vertical constraint being 15pt long.
NSLayoutConstraint:0x859ab20 H:-(13)-|[UIView:0x85a8fb0]...
This would be trailing horizontal constraint etc.
use swift this code
view.translatesAutoresizingMaskIntoConstraints = false
I had quite a number of these exceptions thrown, the fastest and easiest way I found to solve them was to find unique values in the exceptions which I then searched for in the storyboard source code. This helped me to find the actual view(s) and constraint(s) causing the problem (I use meaningful userLabels on all of the views, which makes it a lot easier to track the constraints and views)...
So, using the above exceptions I would open the storyboard as "source code" in xcode (or another editor) and look for something I can find...
<NSLayoutConstraint:0x72bf860 V:[UILabel:0x72bf7c0(17)]>
.. this looks like a vertical (V) constraint on a UILabel with a value of (17).
Looking through the exceptions I also find
<NSLayoutConstraint:0x72c22b0 V:[UILabel:0x72bf7c0]-(NSSpace(8))-[UIButton:0x886efe0]>
Which looks like the UILabel(0x72bf7c0) is close to a UIButton(0x886efe0) with some vertical spacing (8)..
That will hopefully be enough for me to find the specific views in the storyboard source code (probably by searching the text for "17" initially), or at least a few likely candidates. From there I should be able to actually figure out which views these are in the storyboard which will make it a lot easier to identify the problem (look for "duplicated" pinning or pinning that conflicts with size constraints).
I had a hard time figuring out what constraints were causing this error. Here is a simpler way to do it.
I'm using Xcode 6.1.1
"Command + A" to select all the UILabels, UIImages etc.
Click Editor -> Pin > (Select...) to Superview
again click Editor -> Resolve Auto Layout Issues -> Add Missing Constraints or Reset to Suggested Constraints. It depends on your case.
I had this issue because my .xib files were using autolayout.
In the file inspector, first tab. Unticking "Use Autolayout" solved the problem.
Here is my experience and Solution.
I didn't touched code
Select view (UILabel, UIImage etc)
Editor > Pin > (Select...) to Superview
Editor > Resolve Auto Layout Issues > Add Missing Constraints
I have followed SO questions and answers from each search query. But they all are related with specific one.
At the basic, I mean before you are going to write down a format (may be a simple one) it will gives you a warnings.
From iOS 8.0 by default views are size classes. Even if you disable size classes it will still contains some auto layout constraints.
So if you are planning to set constrains via code using VFL. Then you must take care of one below line.
// Remove constraints if any.
[self.view removeConstraints:self.view.constraints];
I had search a lot in SO, but the solution was lies in Apple Sample Code.
So you must have to remove default constraints before planning to add new one.
For me the main reason of this problem was that I forgot to uncheck AutoLayout in the Xib editor.
In fact, I did a lot of adjustments of the XIB in code.
for(UIView *view in [self.view subviews]) {
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
}
This helped me catch the view causing the problem.
None of the foregoing answers is helpful in my situation. I am running XCode 10.1 and testing my app on the simulator for an "iPad (5th generation)". The simulator is running iOS 12.1.
I've got a simple root view in my storyboard, with two UITextField subviews. There are no constraints being used in the storyboard at all. And I have no UIButtonBarView objects in the app or the storyboard.
No messages get printed when the app launches and lays the root view out. None when the simulated device is rotated.
But in the simulator, the moment I click on one of the text fields, the keyboard extension arises from the bottom of the screen, although not the full keyboard, which never seems to show up in the simulator. But the following is printed out on the terminal:
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:0x6000034e7700 h=--& v=--& UIKeyboardAssistantBar:0x7f9c7d714af0.height == 0 (active)>",
"<NSLayoutConstraint:0x6000034aba20 V:|-(0)-[_UIUCBKBSelectionBackground:0x7f9c7d51ec70] (active, names: '|':_UIButtonBarButton:0x7f9c7d51de40 )>",
"<NSLayoutConstraint:0x6000034aba70 _UIUCBKBSelectionBackground:0x7f9c7d51ec70.bottom == _UIButtonBarButton:0x7f9c7d51de40.bottom (active)>",
"<NSLayoutConstraint:0x6000034fb3e0 V:|-(0)-[_UIButtonBarStackView:0x7f9c7d715880] (active, names: '|':UIKeyboardAssistantBar:0x7f9c7d714af0 )>",
"<NSLayoutConstraint:0x6000034fb750 V:[_UIButtonBarStackView:0x7f9c7d715880]-(0)-| (active, names: '|':UIKeyboardAssistantBar:0x7f9c7d714af0 )>",
"<NSLayoutConstraint:0x6000034abc00 'UIButtonBar.maximumAlignmentSize' _UIButtonBarButton:0x7f9c7d51de40.height == UILayoutGuide:0x600002ef4e00'UIViewLayoutMarginsGuide'.height (active)>",
"<NSLayoutConstraint:0x6000034d7cf0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x600002ef4e00'UIViewLayoutMarginsGuide']-(9)-| (active, names: '|':_UIButtonBarStackView:0x7f9c7d715880 )>",
"<NSLayoutConstraint:0x6000034d7c50 'UIView-topMargin-guide-constraint' V:|-(10)-[UILayoutGuide:0x600002ef4e00'UIViewLayoutMarginsGuide'] (active, names: '|':_UIButtonBarStackView:0x7f9c7d715880 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000034aba70 _UIUCBKBSelectionBackground:0x7f9c7d51ec70.bottom == _UIButtonBarButton:0x7f9c7d51de40.bottom (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
It certainly appears to me that all this has to do with nothing in my app, and everything to do with how Apple is creating its own keyboard view, even with my small extension declared to be combined with it.
So the question remains, is there something I as an app developer am responsible for doing (on the presumption this is a bunch of stuff worth attending to) or is it just Apple's own problem/bug?
FWIW, this constraint problem message doesn't occur when simulating a newer iPad model, such as the iPad Pro 12.9-inch (3rd generation). But the message does show up when simulating an iPad Pro 9.7-inch". All claiming they're running iOS 12.1.
I am getting this same error, but only on a specific view, when I touch the first textfield, and then the next textfield down.
I am writing in SwiftUI for iOS 13.4
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:0x2809b6760 'assistantHeight' TUISystemInputAssistantView:0x105710da0.height == 44 (active)>",
"<NSLayoutConstraint:0x2809ccff0 'assistantView.bottom' TUISystemInputAssistantView:0x105710da0.bottom == _UIKBCompatInputView:0x10525ae10.top (active)>",
"<NSLayoutConstraint:0x2809cccd0 'assistantView.top' V:|-(0)-[TUISystemInputAssistantView:0x105710da0] (active, names: '|':UIInputSetHostView:0x105215010 )>",
"<NSLayoutConstraint:0x2809ca300 'inputView.top' V:|-(0)-[_UIKBCompatInputView:0x10525ae10] (active, names: '|':UIInputSetHostView:0x105215010 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2809ccff0 'assistantView.bottom' TUISystemInputAssistantView:0x105710da0.bottom == _UIKBCompatInputView:0x10525ae10.top (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
One thing to watch out for (at least this tripped me up) was that I was removing the constraint from the wrong view. The constraint I was trying to remove was not a child constraint of my view so when I did
myView.removeConstraint(theConstraint)
it wasn't actually removing anything because I needed to call
myView.superView.removeConstraint(theConstraint)
since the constraint was technically sibling constraint of my view.
I was also getting the same issue of breaking constraints in the log, for a viewCircle in the xib. I almost tried everything listed above and nothing was working for me.
Then I tried to change the priority of the Height constraint which was breaking in the log(confirmed by adding an identifiers for the constraints on the xib)enter image description here
Basically, you just have to remove that constraint from the associated view. For instance, if is the height constraint giving warning, just remove it from your view; it will not affect the view.
swift 4
I just add this line in viewDidLoad and work fine with me.
view.removeConstraints(view.constraints)

Resources