【发布时间】:2015-01-11 18:23:36
【问题描述】:
我正在使用 UICollectionView 和子类单元格。单元格是从我布局几个子视图的 xib 加载的。在单元格内,我有一个 BOOL 可以更改其中一个子视图约束。在 iOS 上这有效。但是在iOS 7上,约束改变后,这个子视图的位置是错误的。如果我在控制台中记录信息,则约束设置为 0,但框架显示 188。
我知道 contentView 调整大小存在错误,我通过设置自动调整大小掩码处理得很好。但是这个问题呢。
这是此子视图的约束:
所以在代码内部当BOOL设置为YES时,topConstraint从0设置为(-self.thisSubview.bounds.size.height)。
如果我记录边界高度,它会告诉我它是 130,所以 origin.x 现在应该是 -130 但实际上是 -188。
这是我更改约束的代码:
- (void)setHasInfo:(BOOL)hasInfo {
if (hasInfo) {
self.infoViewTopCon.constant = 0;
[self layoutIfNeeded];
}
else {
self.infoViewTopCon.constant = - self.infoView.bounds.size.height + 4.0;
[self layoutIfNeeded];
}
_hasInfo = hasInfo;
}
【问题讨论】:
-
不知道约束很难判断。
-
leading = superview.leading trailing = superview.trailing height = superview.height top = superview.top
-
更新约束的代码是什么?请将其编辑到您的问题中
标签: ios uicollectionview autolayout uicollectionviewcell nslayoutconstraint