UIView-Encapsulated-Layout-Height and Container View

孤街醉人 提交于 2019-12-22 03:43:57

问题


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


回答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!




回答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.




回答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:

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:

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.




回答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.




回答5:


Set the container view's height constraint. Create an IBOutlet of said height constraint call it "containerViewHeightConstraint" or something. When you update the table view's height constraint to 54, say something like:

self.containerViewHeightConstraint.constant = 54.0;



回答6:


These issues occurs when there is a clash between the constraint.

In your case, you have already given top/bottom leading/trailing constraint to inner table view,which satisfy required constraint for table view, so there is no need of providing one more constraint (fixed height constraint with constant 0) to it.

NSLayoutConstraint:0x7b03e5f0 V:[UITableView:0x7c42a200(54)], NSLayoutConstraint:0x7b0ba120 V:|-(0)-[UITableView:0x7c42a200]

above two line means there is some clash in vertical direction for table view which has constant 0.

Two ways you can resolve this,

1 - Remove height constraint, set bottom constraint to zero initailly. Take an outlet of bottom constraint and set bottom constraint value dynamically.

2 - Remove bottom space constraint, set height constraint to zero. Take an outlet of height constraint and set height of table view dynamically.

Hope this will help you.




回答7:


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)



来源:https://stackoverflow.com/questions/34009447/uiview-encapsulated-layout-height-and-container-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!