Autolayout is complaining about leading/trailing space for UIImageView - ios

I have a UICollectionViewCell in storyboard that has a UIImageView inside of it.
The UICollectionViewCell size is width: 189, height: 239 . The ImageView has the following constraints:
Trailing Space to cell = 31
Leading Space to cell = 31
Bottom Space to cell = 25
Top Space to cell = 31
I receive the following error when running:
2014-11-28 19:53:33.934 AppName[1585:35698] 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:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0]-(31)-| (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSLayoutConstraint:0x7fa4a0d752c0 H:|-(32)-[UIImageView:0x7fa4a0d743e0] (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa4a0d567a0 h=--& v=--& H:[UIView:0x7fa4a0d73d40(50)]>" )
Will attempt to recover by breaking constraint
NSLayoutConstraint:0x7fa4a0d75220
H:[UIImageView:0x7fa4a0d743e0]-(31)-| (Names:
'|':UIView:0x7fa4a0d73d40 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints
to catch this in the debugger. The methods in the
UIConstraintBasedLayoutDebugging category on UIView listed in
may also be helpful.
I tried changing the leading/trailing values in all kinds of ways (tried even/odd numbers) with no success. What is causing this?

This is a known bug in iOS 8 (see this post, Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only). The cell is the correct size that you set in the storyboard, but the cell's content view's size is staying at 50x50, which is why you get the constraint error. It can be fixed by adding this line after you create the cell in cellForItemAtIndexPath:,
cell.contentView.frame = cell.bounds

Related

UIView height not adjusting to subview heights in UITableView header

I have a UITableView with a header view and a custom row. The header view height is not adjusting properly to the constrained heights of its subviews.
The header view container view has the following subviews with constrained heights:
View (this height should compute to 188 but is 128 instead)
Map: UIImage (height = 128)
View: UIView (height = 60)
The header view height should be computed at Map Height + View Height = 128 + 60 = 188 as shown in Storyboard. However running this in the simulator squishes the header view to 128 like this:
Further inspection shows the header view height is 128 and not 188 as expected:
Also the Debug area shows a constraint conflict which shows the header view height is trying to be 128 which conflicts with the heights of its subviews. As a result it squishes the map height:
2015-11-27 16:58:46.415 MyApp[3387:52799] 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:0x7fcb5acf1270 h=--& v=--& V:[UIView:0x7fcb5c246620(128)]>",
"<NSLayoutConstraint:0x7fcb5c24c440 V:[Stop Details Container]-(0)-| (Names: Stop Details Container:0x7fcb5c24c490, '|':UIView:0x7fcb5c246620 )>",
"<NSLayoutConstraint:0x7fcb5c24c6f0 V:[Map]-(0)-[Stop Details Container] (Names: Stop Details Container:0x7fcb5c24c490, Map:0x7fcb5c24aa10 )>",
"<NSLayoutConstraint:0x7fcb5c24c830 V:|-(0)-[Map] (Names: Map:0x7fcb5c24aa10, '|':UIView:0x7fcb5c246620 )>",
"<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)] (Names: Map:0x7fcb5c24aa10 )>",
"<NSLayoutConstraint:0x7fcb5c24c8d0 V:[Stop Details Container(60)] (Names: Stop Details Container:0x7fcb5c24c490 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fcb5c24c880 V:[Map(128)] (Names: Map:0x7fcb5c24aa10 )>
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.
How can I have the header view height properly compute to the heights of its subviews?
In order to force the height of the tableViewHeader I had to manually edit the height property in my Storyboard file with a text editor and this did the trick.
This is most certainly a bug in Xcode 7.1.

UITableViewAutomaticDimension not working properly in iOS 9

In my app I have custom tableViewCells with a fixed ratio (16x9). To achieve that, I placed a view in the cell, fixed it to its parent view (although I did it in interface builder: V/H:|-[innerView]-|).
Also, I put a ratio constraint on it.
In my tableViewController I'm using UITableViewAutomaticDimension as a table cell height.
The estimated row height is 180, wich is the exact size the cell will have on a 320px wide display (as I, as you can see, do).
I'm still deploying for 8.4, but when running the project on an Device with iOS 9, I'm getting tons of auto layout warnings, although everything works fine and looks perfect.
The warning itself is absolutely right. There are two constraints I don't want – these that iOS added on its own.
2015-09-29 11:24:57.771 app[1039:324736] 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:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>",
"<NSLayoutConstraint:0x147dd0210 H:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147deeca0 V:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149053c30 V:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147dbc2b0 H:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>
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 only thing I see here are the missing 0.5 pixels that iOS subtracted somehow magically.
The issue is the two constraints that the tableview adds automatically. UIView-Encapsulated-Layout-Height and width are probably the height and width the table view calculated for the cell during the initial load, based on the cell's constraints at that time.
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
As the priorities for these constraints are 1000 what you can do is lower your height and width constraint priorities and let the encapsulated size to be applied when needed (at load).
Seems you have added two ratio constraints added on two different views.
One that should be there is,
<NSLayoutConstraint:0x14d939e00 UIView:0x14da107f0.width ==
1.77778*UIView:0x14da107f0.height>
has memory address 0x14d939e00 added on UIView with address 0x14da107f0.
The other one is breaking.
<NSLayoutConstraint:0x14c5eae90 UIView:0x14c5ead30.height ==
0.5625*UIView:0x14c5ead30.width>
This one is added on a UIView (0x14c5ead30). Look for this view and remove this ratio constraint.

iOS: Constraint in a custom tableview cell

I have a tableview with a custom cell, where inside it I have a textview.
For this cell I determinate its hight with the size of text and it's ok.
I work in autolayout, so for my cell I use two constraints to expand the textview for all space cell in this way
I can say that it work fine and my textview expand itself for all cell space.
In the view controller I have a control to check when the text (the string) is empty. When it is empty I return 0 for the cell hight.
But in this case when I return 0 and text_view is empty I have a crash but I don't know how to solve.
this is the message
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:0x1704864a0 V:|-(25)-[UITextView:0x15454d960] (Names: '|':UITableViewCellContentView:0x178179680 )>",
"<NSLayoutConstraint:0x1704864f0 V:[UITextView:0x15454d960]-(23)-| (Names: '|':UITableViewCellContentView:0x178179680 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17889a220 h=--& v=--& V:[UITableViewCellContentView:0x178179680(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1704864f0 V:[UITextView:0x15454d960]-(23)-| (Names: '|':UITableViewCellContentView:0x178179680 )>
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.
Set TranslatesAutoresizingMaskIntoConstraints to NO of cell contentView by,
[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];

AutoLayout exceptions iOS6

I am currently using an xib with autolayout to create custom cells in collection view. I have different cell sizes for both orientation. Hence I change the width and height of the cell according to the orientation.
The problem is that when I change the device orientation I get huge number of warnings / exceptions in iOS6.
However when I do the same in iOS7 no warnings are there.
Though it's not affecting my functionality I would like to remove all these warnings.
Here is my XIB file
And following are the errors / warnings /exceptions I am getting.
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:0x164371f0 V:[UILabel:0x16437240(21)]>",
"<NSLayoutConstraint:0x16438050 V:[UILabel:0x16437240]-(1)-[UILabel:0x16437670]>",
"<NSLayoutConstraint:0x16437fd0 V:[UILabel:0x16437670]-(5)-| (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSLayoutConstraint:0x16437f50 V:[UILabel:0x16436e10]-(0)-[UILabel:0x16437240]>",
"<NSLayoutConstraint:0x16437e90 V:|-(7)-[UILabel:0x16436e10] (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x16354d00 h=--& v=--& V:[UICollectionView:0xb24f200(264)]>",
"<NSAutoresizingMaskLayoutConstraint:0x163513b0 h=-&- v=-&- LibraryCollectionViewCell:0x16436ae0.height == UICollectionView:0xb24f200.height - 264>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x164371f0 V:[UILabel:0x16437240(21)]>
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 have tried [cell setTranslatesAutoresizingMaskIntoConstraints:NO] but it crashes the app instead.
Can anyone please provide some solution on this?
"<NSLayoutConstraint:0x164371f0 V:[UILabel:0x16437240(21)]>",
"<NSLayoutConstraint:0x16438050 V:[UILabel:0x16437240]-(1)-[UILabel:0x16437670]>",
"<NSLayoutConstraint:0x16437fd0 V:[UILabel:0x16437670]-(5)-| (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSLayoutConstraint:0x16437f50 V:[UILabel:0x16436e10]-(0)-[UILabel:0x16437240]>",
"<NSLayoutConstraint:0x16437e90 V:|-(7)-[UILabel:0x16436e10] (Names: '|':LibraryCollectionViewCell:0x16436ae0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x16354d00 h=--& v=--& V:[UICollectionView:0xb24f200(264)]>",
"<NSAutoresizingMaskLayoutConstraint:0x163513b0 h=-&- v=-&- LibraryCollectionViewCell:0x16436ae0.height == UICollectionView:0xb24f200.height - 264>"
OK, from your constraints you have...
(Numbers in brackets are last 3 digits of reference).
Label (240) with height constraint fixed to 21.
Label (240) with a vertical gap of 1 to label (670).
Label (670) with a vertical gap of 5 to the superview (ae0) bottom.
Label (e10) with a vertical gap of 7 to the superview (ae0) top.
UICollectionView (200) with fixed height of 264.
LibraryCollectionViewCell (ae0) with an equal height to the collection view - 264 (200).
< Adam Savage >OK! There's your problem!< / Adam Savage >
The last constraint in the list will give the cell a height of 0. (264 - 264 = 0)
However, in the cell you have a label with fixed height 21 and fixed vertical gaps of 7, 5 and 1.
264 - 264 = 0
21 + 7 + 5 + 1 = 36
36 != 0
You can fix this a number of ways. Remove the constraint between the cell and the collection view. Remove the fixed height constraint on the label. etc...
I'd recommend drawing out how you want it to work (on paper) and scribbling in the constraints that you need. Or put a picture of what you are trying to do into your question so we can try to help.
A lot has changed in the way Auto layout takes place from iOS 6.0 to iOS 7.0.
This is quite evident from auto layout implementation via X-Code 4.x & X-Code 5.x.
Since Apple is now expecting apps to be built in X-Code 5.x, I would suggest to go with the same.
Check for the base SDK as well.

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

Resources