What is the UIView-Encapsulated-Layout-Width constraint?

I continue to receive exceptions “It is impossible to simultaneously satisfy restrictions” (Xcode 5, iOS 7, both the device and the simulator), where one of the restrictions in the list looks something like this:

"<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width' H:[StoryPlayerCell:0x165affc0(0)]>" 

I have not set this restriction myself. It is also not an NSAutoresizingMaskLayoutConstraint . But where did it come from? And how can I get rid of him?

I have no idea. And I can't find anything about 'UIView-Encapsulated-Layout-Width' in the Apple documentation. Even a Google search returns nothing.

Any suggestions?

PS: I use this cell in a UICollectionView with a custom subclass of UICollectionViewFlowLayout . Maybe the 'Encapsulated-Layout' has something to do with this?

+46
ios autolayout nslayoutconstraint uicollectionview uicollectionviewlayout
Jan 16 '14 at 12:27
source share
5 answers

A quick and enjoyable fix is ​​to assign a priority value of 999 to user restrictions with high priority. Encapsulated and automatically generated constraints should dominate with higher priority than your constraints.

stack overflow

+16
Sep 17 '14 at 19:39
source share

I played with the sample, I think these codes throw an Autolayout exception.

CGFloat height = MAX(0, -y + maxY); line 79 in CSStickyHeaderFlowLayout.m.

if you use a static value for height, for example 200, an exception will no longer occur. I cannot understand what UIView-Encapsulated-Layout is, but it seems that dynamically changing the UICollectionViewLayoutAttributes frame can cause this problem. in the sample design, this is the height, in the PO task, I assume it is the width. Maybe I can work a little if you think it will be useful

+3
Feb 21 '14 at 8:24
source share

I found this with iOS 10 builds, where I used subclasses of UITableViewCell as regular views, and not as table rows. The cell limited its contentView to zero width.

The workaround I used was to simply add a contentView to the view hierarchy instead of a tableview cell. I also saved the tableView cell (since it was no longer saved by the view hierarchy itself).

+1
Jan 27 '17 at 14:01
source share

I can shed light on the answer to the question. In my OS X application, I found such a cryptic restriction on the presentation of an NSTableView cell (that is, the object I had previously returned to the NSTableViewDelegate -tableView: viewForTableColumn: row method). I also sent the message setWidth: 0.0 to the same column of the table. Changing the parameter in this setWidth: from 0.0 to another was reflected in the constant value of the mysterious constraint.

Conclusion: The restrictions that are registered using "UIView-Encapsulated-Layout-Width" or "NSView-Encapsulated-Layout-Width" are caused by setting the width of the table column or something similar.

0
Jan 24 '16 at 18:04
source share

My situation

I knew (logically) that my software limitations should have worked. I updated them after rotating the device.

My quick and easy solution without changing the restrictions was to make sure that all this was done in the main thread. What for? I'm not too sure, but I assume that the rotation update should be in an asynchronous stream.

How i fixed it

From:

 topTitleLeadingAnchorLandscape.isActive = true 

In order to:

 DispatchQueue.main.async { self.topTitleLeadingAnchorLandscape.isActive = true } 



Hope this saves someone a lot of time in the future! 😀

0
Jan 24 '19 at 22:56
source share



All Articles