场景如下:
在cell上面添加UICollectionView和一些其他的视图,其中UICollectionView的布局如下所示:
collectionView.snp.makeConstraints { (make) in
make.top.equalTo(contentLabel.snp.bottom).offset(10)
make.left.right.equalTo(statusLabel)
make.bottom.equalToSuperview().offset(-15)
make.height.equalTo(COLLECTIONVIEW_HEIGHT)
}
报警告如下:
image.png
原因:
原因是我的cell刚开始高度为0,在某些条件下,会变成另外一个height,然而由于CollectionView会默认添加两个约束就是UIView-Encapsulated-Layout-Width 和UIView-Encapsulated-Layout-Hight保证大小适中,但是我的cell的高度刚开始默认为0,它的系统默认约束和我的设置的约束权限冲突,造成的。
解决办法:降低自己约束权限就行了(约束时使用priorityLow)
// 对collectionView的约束
collectionView.snp.makeConstraints { (make) in
make.top.equalTo(contentLabel.snp.bottom).offset(10)
make.left.right.equalTo(statusLabel)
make.bottom.equalToSuperview().offset(-15).priorityLow()
make.height.equalTo(COLLECTIONVIEW_HEIGHT)
}
// 在某种条件下,更新collectionView的约束
collectionView.snp.updateConstraints { (make) in
make.height.equalTo(temp.height)
make.bottom.equalToSuperview().offset(temp.bottomOffset).priorityLow()
}