1. 问题描述
在布局UITableviewCell 内容时, 可用使用Masonry方便的自动计算高度撑开布局,但是当遇到cell高度不同,多个复杂的子view竖向排列时,容易产生高度计算冲突问题导致报如下一坨

2. 解决办法
使用 Masonry 的 priorityHigh 属性来确定优先级
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
*/
- (MASConstraint * (^)(void))priorityHigh;
具体使用要设置 <最后一个子view> 的 bottom 属性 priorityHigh()
[self.lastView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.topView.mas_bottom).offset(5);
make.left.equalTo(superView).offset(36);
make.right.equalTo(superView).offset(-16);
make.bottom.equalTo(self.contentView).offset(-16).priorityHigh();
}];
本文介绍在使用Masonry进行复杂UI布局时如何解决高度计算冲突的问题。通过设置最后一个子视图的底部约束为高优先级(priorityHigh),可以有效地避免布局冲突,并确保UITableViewCells中的多个子视图能够正确显示。

6819

被折叠的 条评论
为什么被折叠?



