"[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.
The relationship between two user interface objects that must be satisfied by the constraint-based layout system.
translatesAutoresizingMaskIntoConstraints. A Boolean value that determines whether the view's autoresizing mask is translated into Auto Layout constraints.
UIView-Encapsulated-Layout-Width and its counterpart UIView-Encapsulated-Layout-Height is an internal UIKit thingie that's outside your reach. You can't control it, you can't access it, you can't override it.
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:
Since you know where to find unexpected constraints (PBOUserWorkDayHeaderView) there is a way to do this fairly well. Lets find UIView
and NSLayoutConstraint
in red rectangles. Since we know their id in memory it is quite easy.
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)
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
id
you can simple tap it in your Find Navigator:HOW TO SIMPLE FIX THAT CASE?
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.
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
use swift this code
view.translatesAutoresizingMaskIntoConstraints = false
I had this issue because my .xib
files were using autolayout.
In the file inspector, first tab. Unticking "Use Autolayout" solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With