ios - UICollectionViewCell 中的自动布局错误

标签 ios autolayout

我正在尝试调试 UI 中的自动布局冲突。

我已经使用 IB 设置了整个 UI。

我遇到的问题与名为 FrameCellUICollectionView 子类中的对象有关。

FrameCell 有一个 UIImageView 和一个 UILabel,它们都在单元格中水平居中。

垂直约束是这样的...

V:|-20-[UIImageView]-50-[UILabel(==26)]-25-|

UIImageView 的高度是可变的,具体取决于单元格的大小。

但是我收到错误...

( 
    "<NSAutoresizingMaskLayoutConstraint:0x20087d00 h=--& v=--& V:[FrameCell:0x1edaf4a0(0)]>", 
    "<NSLayoutConstraint:0x1edafc10 UIImageView:0x1edaf960.top == FrameCell:0x1edaf4a0.top + 20>", 
    "<NSLayoutConstraint:0x1edafb50 FrameCell:0x1edaf4a0.bottom == UILabel:0x1edaf5c0.bottom + 25>", 
    "<NSLayoutConstraint:0x1edafb10 V:[UIImageView:0x1edaf960]-(50)-[UILabel:0x1edaf5c0]>" 
) 

Will attempt to recover by breaking constraint  
<NSLayoutConstraint:0x1edafb10 V:[UIImageView:0x1edaf960]-(50)-[UILabel:0x1edaf5c0]> 

错误几乎肯定来自 NSAutoresizingMaskLayoutConstraint 但我不确定如何摆脱它?!为什么要将 FrameCell 高度设置为 0?!

如果我尝试在 Cell 中关闭 translatesAutoresizingMaskIntoConstraints,我会收到内部一致性错误。我正在使用 IB 设置所有内容,所以我不确定这个 AutoResizingMask 是从哪里来的?

最佳答案

我想知道 IB 在处理 UICollectionViewCells 中的约束时是否会遇到与处理 UITableViewCells 时相同的问题?

请参阅@Adrians 对这个问题的回答:contentView not indenting in iOS 6 UITableViewCell prototype cell

关于ios - UICollectionViewCell 中的自动布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650151/

相关文章:

iOS 自动布局错位 View 偏移一个错误

ios - 如何根据 UITableView 的高度给 UITableViewCell 高度百分比?然后所有的 UITableViewCell 都可以不滚动显示出来

ios - UITabBar 中的 UICollectionView 在第一次加载时显示错误的位置

ios - 以 UILabel 文本的第一行居中图像

ios - 有些 UIColors 是黑色的,而不是它们应该的样子,为什么?

ios - RACObserve(), RAC() - 如何根据 NSString 设置 BOOL 值

ios - 具有 anchor 样式自动布局约束的 UIButtons 未显示

ios - AutoLayout - 将 UILabel 的大小调整到它的 Superview 并调整它的大小

ios - 使用 WKWebViewConfiguration 将属性 selectionGranularity 设置为 .Character 时会出现无文本选择 View 的错误

objective-c - 使用 UIViewController 调用多个 ViewController