UIView-Encapsulated-Layout-Height and Container View

13,193

Solution 1

Finally i solve this problem.
1. In your tableView setting, set: tableView.estimatedRowHeight = 100.
2. In the last view of your cell, set: make.bottom.equalTo(contentView).priority(999).
3. Run your code, maybe it's ok!

Solution 2

Finally i found a problem. View that is added as subview to container view has translatesAutoresizingMaskIntoConstraints = YES, so NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)] was appeared and made me some problems. Add runtime attribute translatesAutoresizingMaskIntoConstraints = NO and it'll fix the issue.

Solution 3

Chiming in with one of the easiest ways to solve this: Just lower the priority of the autolayout rule that is bound to the bottom edge of your container view.

Here's my container:

enter image description here

I'm telling that image view to follow the bottom edge of the container, and that was giving me a conflict. To fix it, I can just lower the priority of that bottom edge rule:

enter image description here

I say "bottom" because in my estimation that's probably the one you'll have a conflict with, but it could be any edge that implicitly sets a width on your container.

Solution 4

Rather than manually setting translatesAutoresizingMaskIntoConstraints on the contentView of the cell or manually adjusting the height of this view, you should just set estimatedRowHeight and rowHeight for the tableview, as discussed in WWDC 2014 video What's New in Table and Collection Views:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.estimatedRowHeight = 44;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

Then the fully qualified constraints you apply to that cell will adjust the row height and eliminate those annoying warnings.

Solution 5

Go on the item's container's xib -> deselect "Autoresize Subviews" under the "drawing" section. It fixed it for me. (The item is the item that's giving you the constraints conflict)

drawing

Share:
13,193
Serd
Author by

Serd

Updated on June 12, 2022

Comments

  • Serd
    Serd almost 2 years

    I have UIViewController 1 , that has scroll view. Inside this scrollview there is container view that pinned to top/bottom leading/trailing (without fixed height). Container view has UITableView pinned to top/bottom trailing/leading and height constraint with 0 constant, that will change in updateViewConstraints to content size height.

    When View of UIViewController 1 appears, Container View has constraint:

    NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)], NSLayoutConstraint:0x7b0ba120 V:|-(0)-[UITableView:0x7c42a200] (Names: '|':UIView:0x7b0b7000 ), NSLayoutConstraint:0x7b0ba1b0 V:[UITableView:0x7c42a200]-(0)-| (Names: '|':UIView:0x7b0b7000 ), NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)]

    Will attempt to recover by breaking constraint

    NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)]

    What is UIView-Encapsulated-Layout-Height? How can i skip it?Because it breaks "right" constraint(that i update to content size height).Thanks

  • Serd
    Serd over 8 years
    Thanks for answer, but containerViewHeightConstraint and TableViewConstraint are in different view controllers. How can i know in view controller 1 ,when tableview constraint changed?Thanks
  • beyowulf
    beyowulf over 8 years
    You can use delegation or NSNotificationCenter
  • Serd
    Serd over 8 years
    It's bad approach, i hope(and sure) that there is better solution.Nevertheless Thanks
  • beyowulf
    beyowulf over 8 years
    Really the bad approach is using child view controllers. You should avoid that practice. But I tried to tell you, what you're saying makes no sense. You're pinning everything to the edges then setting the height to zero, you must be getting warnings or errors from auto layout. You should investigate those.
  • Serd
    Serd over 8 years
    I only have working from scroll view, where container is pinned, because scroll view can not determine it's content size. But what i want - is that container view has height base on the content it's represent. Thanks
  • Serd
    Serd over 8 years
    The main problem for me is this constraint - NSLayoutConstraint:0x7b65f900 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7b0b7000(0)
  • João Nunes
    João Nunes over 8 years
    This solved my problem! After the container view is added. Use the prepareForSegue method to get to the view,then set to false the translatesAutoresizingMaskIntoConstraints of that view
  • Serd
    Serd over 8 years
    it also can be set in interface builder in runtime attributes
  • Protongun
    Protongun almost 8 years
    Thank you! I was adding a child view controller (not using container views, explicitly in code) and I had forgotten to set the child VC's view's translatesAutoresizingMaskIntoConstraints property to false
  • Kyle Browning
    Kyle Browning about 6 years
    Holy crap I searched for a long time and this actually worked.
  • Thippi
    Thippi almost 6 years
    Thanks , its really helped to me, I searched alot for this issue
  • Diego Carrera
    Diego Carrera over 5 years
    Thank you, It worked great and the warning disappeared.
  • Robert Haworth
    Robert Haworth over 5 years
    Lowering the priority of your final connecting constraint to the cell's contentView is exactly the right answer it seems. This also holds true for UICollectionViewCell's if you see this same issue.
  • Asike
    Asike about 4 years
    Thanks! With SnapKit I made $0.bottom.equalToSuperview().offset(-5).priority(.low)