iOS UITableView设置tableHeaderView时发生约束错误 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width
2017-07-28 15:03
2691 查看
在将UITableView的tableHeaderView设置为我自己创建的View的时候,
当我为这个自定义View添加约束之后启动调试,
然后符号断点UIViewAlertForUnsatisfiableConstraints命中了,
终端输出了如下的报错信息:
这其实是CollectionView为你的自定义View自动添加了其他约束,
然而它添加的约束和你添加的约束的优先级是相同的。
所以解决问题的关键就是将你设置的约束的优先级降低;
解决方案参考:
一、如果你使用了UIKit提供的API来设置约束,可以参考如下OC代码:
二、如果你使用了SnapKit来设置约束,可以参考如下Swift代码:
参考资料:http://blog.csdn.net/hello_hwc/article/details/47129711
转载请注明出处:http://www.cnblogs.com/ficow/p/7250330.html
当我为这个自定义View添加约束之后启动调试,
然后符号断点UIViewAlertForUnsatisfiableConstraints命中了,
终端输出了如下的报错信息:
( "<SnapKit.LayoutConstraint:0x1702a64e0@MAskDetailVC.swift#120 UIView:0x1017eb5e0.height == 211.666666666667>", "<NSLayoutConstraint:0x170682760 'UIView-Encapsulated-Layout-Height' UIView:0x1017eb5e0.height == 212 (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x170682760 'UIView-Encapsulated-Layout-Height' UIView:0x1017eb5e0.height == 212 (active)>
这其实是CollectionView为你的自定义View自动添加了其他约束,
然而它添加的约束和你添加的约束的优先级是相同的。
所以解决问题的关键就是将你设置的约束的优先级降低;
解决方案参考:
一、如果你使用了UIKit提供的API来设置约束,可以参考如下OC代码:
NSArray * collectionConstraints_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_collectionview]-0-|" options:0 metrics:nil views:viewsDic]; [self addConstraints:collectionConstraints_V]; NSArray * collectionConstraints_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-103-[_collectionview]" options:0 metrics:nil views:viewsDic]; [self addConstraints:collectionConstraints_H]; NSLayoutConstraint * constraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[_collectionview]-0-|" options:0 metrics:nil views:viewsDic].firstObject; constraint.priority = UILayoutPriorityDefaultLow; [self addConstraint:constraint];
二、如果你使用了SnapKit来设置约束,可以参考如下Swift代码:
askContainer.snp.makeConstraints { (m) in m.top.equalTo(detailTV.snp.top) m.leading.equalTo(detailTV.snp.leading) m.width.equalTo(SCREEN_WIDTH) let height = m.height.equalTo(height).constraint height.layoutConstraints.first?.priority = UILayoutPriorityDefaultLow }
参考资料:http://blog.csdn.net/hello_hwc/article/details/47129711
转载请注明出处:http://www.cnblogs.com/ficow/p/7250330.html
相关文章推荐
- 使用autolayout设置UITableView的tableHeaderView
- iOS开发-利用xib怎么为UITableView 设置tableHeaderView
- 如何用约束设置UITableView的tableHeaderView,其中tableHeaderView的高度是动态变化的
- 关于设置 UITableView 的 tableHeaderView为使用了 SnapKit 约束的自定义 view 时出现的 BUG 的处理
- - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- iOS设置tableViewCell之间的间距(去掉UItableview headerview黏性)
- [iOS]对TableHeaderView添加约束后适配高度
- iOS UITableView动态改变tableHeaderView的高度
- iOS UITableView(四) 为tableView设置头尾视图,改变cell的宽度,cell的缩进
- ios:改变tableview的titleForHeaderInSection字体颜色设置
- UITableView tableHeaderView autolayout自动计算高度
- 在xib里,拖一个UIView到UITableView中作为tableHeaderView
- iOS开发-去掉UITableView HeaderView或FooterView随tableView 移动的黏性(sticky
- iOS-UITableView 之 tableHeaderView 遮挡后面 cell 的问题
- iOS storyboard中设置TableView的headerview 和 footerview
- iOS 设置一行颜色不同的NSString 、剪切图片、设置TableView的自定义header
- IOS第七天(4:UiTableView 数据的显示优化重复实例和tableFooterView和tableHeaderView)
- ios开发之--ios11适配:TableView的heightForHeaderInSection设置高度无效/UISearchBar消失
- 在xib里,拖一个UIView到UITableView中作为tableHeaderView
- iOS之设置tableView背景图片/让UITableView自动滑动(定位)到某一行cell