AutoLayout inside of an AutoResizingView - ios

I am trying to create a custom inputView for a UITextView. I have a subclass of a UIView that I am working in, and I'm trying to add UI elements to it. The view itself is set to self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; so that the system will fill the view to the size of what the inputView should be.
I can't seem to get AutoLayout constraints to work inside of this view. No matter how many different things I try, I always have conflicting constraints.
Is it possible to use AutoLayout inside of an autoresizing view?
Here is some sample code of what I'm doing:
UILabel *label = [[UILabel alloc] init];
label.text = #"Test Label";
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label];
NSArray *labelHorizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:#"H:|-8.0-[label]-8.0-|" options:0 metrics:nil views:#{ #"label" : label }];
NSArray *labelVerticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:#"V:|-8.0-[label]" options:0 metrics:nil views:#{ #"label" : label }];
NSMutableArray *constraintsArray = [NSMutableArray array];
[constraintsArray addObjectsFromArray:labelHorizontalConstraints];
[constraintsArray addObjectsFromArray:labelVerticalConstraints];
[self addConstraints:constraintsArray];
And this is the kind of errors that I'm getting:
2015-07-21 05:56:38.804 InputView[880:22401] 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:0x79175910 UIInputSetHostView:0x79175640.width == UIInputSetContainerView:0x79174ff0.width>",
"<NSLayoutConstraint:0x78f8f240 'UIView-Encapsulated-Layout-Width' H:[UIInputSetContainerView:0x79174ff0(768)]>",
"<NSLayoutConstraint:0x7932ffa0 H:|-(8)-[UILabel:0x79364df0'Test Label'] (Names: '|':TestInputView:0x79364f10 )>",
"<NSLayoutConstraint:0x7932d1a0 H:[UILabel:0x79364df0'Test Label']-(8)-| (Names: '|':TestInputView:0x79364f10 )>",
"<NSLayoutConstraint:0x793611b0 TestInputView:0x79364f10.right == UIInputSetHostView:0x79175640.right>",
"<NSLayoutConstraint:0x79361180 H:|-(0)-[TestInputView:0x79364f10](LTR) (Names: '|':UIInputSetHostView:0x79175640 )>",
"<NSAutoresizingMaskLayoutConstraint:0x79362920 h=--& v=--& UILabel:0x79364df0'Test Label'.midX ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7932d1a0 H:[UILabel:0x79364df0'Test Label']-(8)-| (Names: '|':TestInputView:0x79364f10 )>
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.
2015-07-21 05:56:38.805 InputView[880:22401] 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:0x7932ffa0 H:|-(8)-[UILabel:0x79364df0'Test Label'] (Names: '|':TestInputView:0x79364f10 )>",
"<NSAutoresizingMaskLayoutConstraint:0x79362920 h=--& v=--& UILabel:0x79364df0'Test Label'.midX ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7932ffa0 H:|-(8)-[UILabel:0x79364df0'Test Label'] (Names: '|':TestInputView:0x79364f10 )>
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.
2015-07-21 05:56:38.812 InputView[880:22401] 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:0x7932e7e0 V:|-(8)-[UILabel:0x79364df0'Test Label'] (Names: '|':TestInputView:0x79364f10 )>",
"<NSAutoresizingMaskLayoutConstraint:0x79362980 h=--& v=--& UILabel:0x79364df0'Test Label'.midY ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7932e7e0 V:|-(8)-[UILabel:0x79364df0'Test Label'] (Names: '|':TestInputView:0x79364f10 )>
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 help would be appreciated. Thanks.

Set translatesAutoresizingMaskIntoConstraints for label to false:
label.setTranslatesAutoresizingMaskIntoConstraints(false)
See Adopting Auto Layout:
For views that are aware of Auto Layout, in most circumstances you
want translatesAutoresizingMaskIntoConstraints to be NO. The reason is
that the constraints generated by translating the autoresizing mask
are already sufficient to completely specify the frame of a view given
its superview’s frame, which is generally too much. For example, this
translation would prevent a button from automatically assuming its
optimal width when its title is changed.
From experience, forgetting to set that flag on programmatically created views has to be the number one cause of constraint exceptions.
To answer your question regarding mixing Auto Layout and Auto Resizing; both can be freely mixed and matched. However it's not correct to say that your project is using both. If you have Auto Layout enabled, that applies to the entire project. Views may still be configured using Auto Resizing, but what is actually happening is that those specifications are being translated into Auto Layout constraints. The problem above is that you have the Auto Resizing view - label - with it's translated constraints, conflicting with additional Auto Layout constraints that you specify.

Related

Getting error when apply auto layout

I have a UICollectionView and a UILabel that I added constraints programmatically.
[_labelToChange setTranslatesAutoresizingMaskIntoConstraints:NO];
[_datesCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-0-[_labelToChange(30)]-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange, _datesCollectionView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-0-[_labelToChange]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_datesCollectionView)]];
When I do that, I get the following error:
2015-06-05 11:07:37.013 myApp[602:10299] 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:0x7f87c1580420 V:[DIDatepicker:0x7f87c157fda0(94)]>",
"<NSLayoutConstraint:0x7f87c1580560 V:|-(0)-[DIDatepicker:0x7f87c157fda0] (Names: '|':UITableViewCellContentView:0x7f87c157f760 )>",
"<NSLayoutConstraint:0x7f87c1580600 V:[DIDatepicker:0x7f87c157fda0]-(0)-| (Names: '|':UITableViewCellContentView:0x7f87c157f760 )>",
"<NSLayoutConstraint:0x7f87c157ed80 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f87c157f760(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f87c1580420 V:[DIDatepicker:0x7f87c157fda0(94)]>
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.
2015-06-05 11:07:37.018 myApp[602:10299] 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:0x7f87c1580560 V:|-(0)-[DIDatepicker:0x7f87c157fda0] (Names: '|':UITableViewCellContentView:0x7f87c157f760 )>",
"<NSLayoutConstraint:0x7f87c1580600 V:[DIDatepicker:0x7f87c157fda0]-(0)-| (Names: '|':UITableViewCellContentView:0x7f87c157f760 )>",
"<NSLayoutConstraint:0x7f87c15a95f0 V:|-(0)-[UILabel:0x7f87c15a8840] (Names: '|':DIDatepicker:0x7f87c157fda0 )>",
"<NSLayoutConstraint:0x7f87c15a9790 V:[UILabel:0x7f87c15a8840(30)]>",
"<NSLayoutConstraint:0x7f87c15a98e0 V:[UILabel:0x7f87c15a8840]-(0)-[UICollectionView:0x7f87c1959000]>",
"<NSLayoutConstraint:0x7f87c15a9930 V:[UICollectionView:0x7f87c1959000]-(0)-| (Names: '|':DIDatepicker:0x7f87c157fda0 )>",
"<NSLayoutConstraint:0x7f87c157ed80 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f87c157f760(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f87c15a98e0 V:[UILabel:0x7f87c15a8840]-(0)-[UICollectionView:0x7f87c1959000]>
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.
What can I do to fix it?
Update
Thanks #rdelmar!! I did what #rdelmar said, and I now 1 error goes away but the other is still there:
2015-06-05 12:52:14.102 myApp[2373:44139] 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:0x7fa2e1d80470 V:[DIDatepicker:0x7fa2e1d7fd10]-(0)-| (Names: '|':UITableViewCellContentView:0x7fa2e1d7f6d0 )>",
"<NSLayoutConstraint:0x7fa2e1d80510 V:|-(0)-[DIDatepicker:0x7fa2e1d7fd10] (Names: '|':UITableViewCellContentView:0x7fa2e1d7f6d0 )>",
"<NSLayoutConstraint:0x7fa2e1da9740 V:|-(0)-[UILabel:0x7fa2e1da8970] (Names: '|':DIDatepicker:0x7fa2e1d7fd10 )>",
"<NSLayoutConstraint:0x7fa2e1da9990 V:[UILabel:0x7fa2e1da8970]-(0)-[UICollectionView:0x7fa2e20f8e00]>",
"<NSLayoutConstraint:0x7fa2e1da9a10 V:[UICollectionView:0x7fa2e20f8e00(85)]>",
"<NSLayoutConstraint:0x7fa2e1da9a60 V:[UICollectionView:0x7fa2e20f8e00]-(0)-| (Names: '|':DIDatepicker:0x7fa2e1d7fd10 )>",
"<NSLayoutConstraint:0x7fa2e1da4a50 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fa2e1d7f6d0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fa2e1da9990 V:[UILabel:0x7fa2e1da8970]-(0)-[UICollectionView:0x7fa2e20f8e00]>

Auto Layout issue with collection view cell

I am trying to create a somewhat basic layout and am having the classic "Unable to simultaneously satisfy constraints" problem. After an hour on it I cannot track it down.
Here is the layout in interface builder:
Please note that no constraints are being added/modified in code. Everything is happening in IB.
Here is the error message I am getting:
2015-03-07 19:13:33.044 TwitterStats[4326:209207] 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:0x7f888ad8b700 H:[UIImageView:0x7f888ad8ce40(90)]>",
"<NSLayoutConstraint:0x7f888ad8f910 H:|-(8)-[UIImageView:0x7f888ad8ce40] (Names: '|':UIView:0x7f888ad8cd70 )>",
"<NSLayoutConstraint:0x7f888ad8fb40 UIView:0x7f888ad8cd70.trailingMargin == UILabel:0x7f888ad87790'#username'.trailing + 10>",
"<NSLayoutConstraint:0x7f888ad8fb90 H:[UIImageView:0x7f888ad8ce40]-(14)-[UILabel:0x7f888ad87790'#username']>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af29690 h=--& v=--& H:[UIView:0x7f888ad8cd70(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ad8b700 H:[UIImageView:0x7f888ad8ce40(90)]>
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.
2015-03-07 19:13:33.045 TwitterStats[4326:209207] 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:0x7f888ad8b210 V:[UIImageView:0x7f888ad8ce40(90)]>",
"<NSLayoutConstraint:0x7f888ad8f450 V:[UIButton:0x7f888ad8f150'Unfollow'(52)]>",
"<NSLayoutConstraint:0x7f888ad8f8c0 V:|-(8)-[UIImageView:0x7f888ad8ce40] (Names: '|':UIView:0x7f888ad8cd70 )>",
"<NSLayoutConstraint:0x7f888ad8fa00 V:[UIImageView:0x7f888ad8ce40]-(10)-[UITableView:0x7f888b840000]>",
"<NSLayoutConstraint:0x7f888ad8fc30 V:[UITableView:0x7f888b840000]-(0)-[UIButton:0x7f888ad8f150'Unfollow']>",
"<NSLayoutConstraint:0x7f888ad8fcd0 V:[UIButton:0x7f888ad8f150'Unfollow']-(0)-| (Names: '|':UIView:0x7f888ad8cd70 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af3cb10 h=--& v=--& V:[UIView:0x7f888ad8cd70(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ad8b210 V:[UIImageView:0x7f888ad8ce40(90)]>
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.
2015-03-07 19:13:33.073 TwitterStats[4326:209207] 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:0x7f888ad8f450 V:[UIButton:0x7f888ad8f150'Unfollow'(52)]>",
"<NSLayoutConstraint:0x7f888ad8f8c0 V:|-(8)-[UIImageView:0x7f888ad8ce40] (Names: '|':UIView:0x7f888ad8cd70 )>",
"<NSLayoutConstraint:0x7f888ad8fa00 V:[UIImageView:0x7f888ad8ce40]-(10)-[UITableView:0x7f888b840000]>",
"<NSLayoutConstraint:0x7f888ad8fc30 V:[UITableView:0x7f888b840000]-(0)-[UIButton:0x7f888ad8f150'Unfollow']>",
"<NSLayoutConstraint:0x7f888ad8fcd0 V:[UIButton:0x7f888ad8f150'Unfollow']-(0)-| (Names: '|':UIView:0x7f888ad8cd70 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af3cb10 h=--& v=--& V:[UIView:0x7f888ad8cd70(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ad8f450 V:[UIButton:0x7f888ad8f150'Unfollow'(52)]>
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.
2015-03-07 19:13:33.111 TwitterStats[4326:209207] 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:0x7f888ac441e0 H:[UIImageView:0x7f888ac87610(90)]>",
"<NSLayoutConstraint:0x7f888ac4f8e0 H:|-(8)-[UIImageView:0x7f888ac87610] (Names: '|':UIView:0x7f888ac7f2c0 )>",
"<NSLayoutConstraint:0x7f888ac8cd20 UIView:0x7f888ac7f2c0.trailingMargin == UILabel:0x7f888ac52b00'#username'.trailing + 10>",
"<NSLayoutConstraint:0x7f888ac48b90 H:[UIImageView:0x7f888ac87610]-(14)-[UILabel:0x7f888ac52b00'#username']>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af3e030 h=--& v=--& H:[UIView:0x7f888ac7f2c0(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ac441e0 H:[UIImageView:0x7f888ac87610(90)]>
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.
2015-03-07 19:13:33.113 TwitterStats[4326:209207] 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:0x7f888ac29530 V:[UIImageView:0x7f888ac87610(90)]>",
"<NSLayoutConstraint:0x7f888ac41d40 V:[UIButton:0x7f888ac53e90'Unfollow'(52)]>",
"<NSLayoutConstraint:0x7f888ac4f890 V:|-(8)-[UIImageView:0x7f888ac87610] (Names: '|':UIView:0x7f888ac7f2c0 )>",
"<NSLayoutConstraint:0x7f888ac8b790 V:[UIImageView:0x7f888ac87610]-(10)-[UITableView:0x7f888b035400]>",
"<NSLayoutConstraint:0x7f888ac48c30 V:[UITableView:0x7f888b035400]-(0)-[UIButton:0x7f888ac53e90'Unfollow']>",
"<NSLayoutConstraint:0x7f888ac8ae40 V:[UIButton:0x7f888ac53e90'Unfollow']-(0)-| (Names: '|':UIView:0x7f888ac7f2c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af2ba00 h=--& v=--& V:[UIView:0x7f888ac7f2c0(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ac29530 V:[UIImageView:0x7f888ac87610(90)]>
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.
2015-03-07 19:13:33.114 TwitterStats[4326:209207] 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:0x7f888ac41d40 V:[UIButton:0x7f888ac53e90'Unfollow'(52)]>",
"<NSLayoutConstraint:0x7f888ac4f890 V:|-(8)-[UIImageView:0x7f888ac87610] (Names: '|':UIView:0x7f888ac7f2c0 )>",
"<NSLayoutConstraint:0x7f888ac8b790 V:[UIImageView:0x7f888ac87610]-(10)-[UITableView:0x7f888b035400]>",
"<NSLayoutConstraint:0x7f888ac48c30 V:[UITableView:0x7f888b035400]-(0)-[UIButton:0x7f888ac53e90'Unfollow']>",
"<NSLayoutConstraint:0x7f888ac8ae40 V:[UIButton:0x7f888ac53e90'Unfollow']-(0)-| (Names: '|':UIView:0x7f888ac7f2c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7f888af2ba00 h=--& v=--& V:[UIView:0x7f888ac7f2c0(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f888ac41d40 V:[UIButton:0x7f888ac53e90'Unfollow'(52)]>
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.
The strange thing is this constraint <NSAutoresizingMaskLayoutConstraint:0x7f888af2ba00 h=--& v=--& V:[UIView:0x7f888ac7f2c0(50)]>, I don't get where it's coming from.
Any idea on how to solve these issues?
I had same problem yesterday. The NSAutoresizingMaskLayoutConstraint you mentioned was not the problem. I could not figure out where that constraint comes from, but it seems to be normal for collection view cells.
The problem is that the constraints cannot be satisfied. Take a look at the first set of constraints that are not working:
"<NSLayoutConstraint:0x7f888ad8b700 H:[UIImageView:0x7f888ad8ce40(90)]"
"<NSLayoutConstraint:0x7f888ad8f910 H:|-(8)-[UIImageView:0x7f888ad8ce40] (Names: '|':UIView:0x7f888ad8cd70 )>"
"<NSLayoutConstraint:0x7f888ad8fb40 UIView:0x7f888ad8cd70.trailingMargin == UILabel:0x7f888ad87790'#username'.trailing + 10>"
"<NSLayoutConstraint:0x7f888ad8fb90 H:[UIImageView:0x7f888ad8ce40]-(14)-[UILabel:0x7f888ad87790'#username']>"
You have 8 points from the left edge to the image view.
The image view is 90 points wide. You have 14 points from the image view to the username. Then the username is constrained to the trailing margin with 10 points space.
Username is a UILabel and has intrinsic size. Suppose that for a given user it required 40 points to display the username. Your constraints would result in a screen width of 8 + 90 + 14 + 40 + 10 = 162. That would be a very narrow screen! These constraints cannot be satisfied.
The thing to do here is remove this trailing constraint:
"<NSLayoutConstraint:0x7f888ad8fb40 UIView:0x7f888ad8cd70.trailingMargin == UILabel:0x7f888ad87790'#username'.trailing + 10>"
If you are really concerned that the username could be too long, you could try keeping this constraint, but changing it from EQUALS 10 to GREATER THAN OR EQUAL to 10.
I had a similar problem with a UICollectionView in a Storyboard.
The cause for this error is the size of the contentView of the CollectionViewCell. It uses the default size which is (50.0, 50.0). This might be an InterfaceBuilder-Bug.
A fix is to change the priority for your imageView.width (90) and the buttons width (52) to 999.

Autolayout constraints warning “Will attempt to recover by breaking constraint”

I am trying to implement a feed of news (somehow like instagram without comments or likes). It works, but xcode keep showing this error. I tried change all the constraints, however, I cant get to work. The tableview has a height of 475 and the image has the height of 400, leaving 75 for the white area with labels.
I did use
self.tableView.estimatedRowHeight = 475;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Any help?
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:0x174096530 UIImageView:0x1743e9000.top == UITableViewCellContentView:0x17418af80.topMargin + 13>",
"<NSLayoutConstraint:0x1740977f0 V:[PFImageView:0x1743e8e00]-(0)-| (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097840 V:[UIImageView:0x1743e9000]-(24)-[PFImageView:0x1743e8e00]>",
"<NSLayoutConstraint:0x174097890 H:|-(0)-[PFImageView:0x1743e8e00] (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097930 H:[PFImageView:0x1743e8e00]-(0)-| (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097ac0 PFImageView:0x1743e8e00.width == PFImageView:0x1743e8e00.height>",
"<NSLayoutConstraint:0x174097b60 V:[UIImageView:0x1743e9000(30)]>",
"<NSLayoutConstraint:0x174092ed0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x17418af80(375)]>",
"<NSLayoutConstraint:0x174092f20 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17418af80(44)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174097b60 V:[UIImageView:0x1743e9000(30)]>
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 actually solved the problem changing the priority from the bottom of the image constrain to 750. Thanks for the help.

ios add button autolayout

I insert a button to a view in storyboard like following:
and I need to add a custom constrain to the bottom using following code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *viewsDictionary = [NSDictionary dictionaryWithObject:self.bottomButton forKey:#"bottomButton"];
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"[bottomButton]-90-|" options:0 metrics:nil views:viewsDictionary];
NSArray *v_constraints = [NSLayoutConstraint constraintsWithVisualFormat:#"V:[bottomButton]-20-|" options:0 metrics:nil views:viewsDictionary];
[self.bottomButton.superview addConstraints:constraints];
[self.bottomButton.superview addConstraints:v_constraints];
}
but there's a conflict, the error is
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:0x8c57fb0 'IB auto generated at build time for view with fixed frame' H:|-(254)-[UIButton:0x8c56440](LTR) (Names: '|':UIView:0x8c56af0 )>",
"<NSIBPrototypingLayoutConstraint:0x8c58de0 'IB auto generated at build time for view with fixed frame' H:[UIButton:0x8c56440(46)]>",
"<NSLayoutConstraint:0x8c4fc30 H:[UIButton:0x8c56440]-(90)-| (Names: '|':UIView:0x8c56af0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8c62320 h=--& v=--& H:[UIView:0x8c56af0(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8c4fc30 H:[UIButton:0x8c56440]-(90)-| (Names: '|':UIView:0x8c56af0 )>
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.
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:0x8c58d30 'IB auto generated at build time for view with fixed frame' V:|-(361)-[UIButton:0x8c56440] (Names: '|':UIView:0x8c56af0 )>",
"<NSIBPrototypingLayoutConstraint:0x8c58e10 'IB auto generated at build time for view with fixed frame' V:[UIButton:0x8c56440(30)]>",
"<NSLayoutConstraint:0x8c527c0 V:[UIButton:0x8c56440]-(20)-| (Names: '|':UIView:0x8c56af0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8c62380 h=--& v=--& V:[UIView:0x8c56af0(568)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8c527c0 V:[UIButton:0x8c56440]-(20)-| (Names: '|':UIView:0x8c56af0 )>
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.
how to fix it?
It's happening because even though you haven't set constraints explicitly in IB they're automatically added on runtime, e.g.
"<NSIBPrototypingLayoutConstraint:0x8c57fb0 'IB auto generated at build time for view with fixed frame' H:|-(254)-[UIButton:0x8c56440](LTR) (Names: '|':UIView:0x8c56af0 )>",
Please watch the session 406 from WWDC 2013. The current best practice is to set your constraints in IB, and then only modify/add constraints in code which can't be set using IB.

Programmatically attempting NSLayoutContraint gives "Unable to simultaneously satisfy constraints."

I seem to be having some problems settings up my constraints programmatically for a UITableView I am using. My attempt is below, and have tried every combination of using the translatesAutoresizingMaskIntoConstraints possible.
self.view.translatesAutoresizingMaskIntoConstraints = NO;
_tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|-100-[_tableView]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];
I am just trying to add a space to the beginning and bottom of my UITableView on a UIViewController. Could anyone help with this?
The long, long error is below.
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:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
"<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-| (Names: '|':UIView:0x71a4ec0 )>",
"<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400] (Names: '|':UIView:0x71a4ec0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-| (Names: '|':UIView:0x71a4ec0 )>
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.
2013-04-04 20:06:57.648 New eCard[29731: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:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
"<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
"<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400] (Names: '|':UIView:0x71a4ec0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400] (Names: '|':UIView:0x71a4ec0 )>
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.
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:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
"<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
"<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-| (Names: '|':UIView:0x71a4ec0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-| (Names: '|':UIView:0x71a4ec0 )>
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 found this issue about UICollectionView. I guess that is a good point to start debugging.
UICollectionView Cell + UiLabel with AutoLayout
Some other links with solutions I tried without success :
https://blog.safaribooksonline.com/2012/10/27/tip-unsatisfiable-auto-layouts-in-ios-6/
UITableView with autolayout and offset constraints

Resources