我的布局约束在 Interface Builder 中很好,但由于框架的某些部分应用了我真正不想要的固定高度和宽度约束,因此在运行时发生异常。它们为何存在以及如何将其关闭?
它们是记录列表中显示的最后两个约束:
2014-04-26 09:02:58.687 BBCNews[32058:60b] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0xbf478a0 UIView:0xbf4a3c0.height == 0.28125*UIView:0xbf4a3c0.width>",
"<NSLayoutConstraint:0xbf47190 UIView:0xbf4a3c0.leading == BNMyNewsCell_landscape:0xbf48b10.leading>",
"<NSLayoutConstraint:0xbf47160 UIView:0xbf4a3c0.trailing == BNMyNewsCell_landscape:0xbf48b10.trailing>",
"<NSLayoutConstraint:0xbf47130 BNMyNewsCell_landscape:0xbf48b10.bottom == UIView:0xbf4a3c0.bottom>",
"<NSLayoutConstraint:0xbf47100 UIView:0xbf4a3c0.top == BNMyNewsCell_landscape:0xbf48b10.top>",
"<NSLayoutConstraint:0xd4c3c40 'UIView-Encapsulated-Layout-Width' H:[BNMyNewsCell_landscape:0xbf48b10(304)]>",
"<NSLayoutConstraint:0xd4c38a0 'UIView-Encapsulated-Layout-Height' V:[BNMyNewsCell_landscape:0xbf48b10(290)]>"
}
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xbf478a0 UIView:0xbf4a3c0.height == 0.28125*UIView:0xbf4a3c0.width>
基于大量的观察,我相信(但不能确定)名为的约束UIView-Encapsulated-Layout-Width
and UIView-Encapsulated-Layout-Height
是由创建的UICollectionView
和朋友,并存在以强制返回的大小sizeForItemAtIndexPath
委托方法。我想它的存在是为了确保UICollectionViewCell
由设置cellForItemAtIndexPath
最终达到了它被告知的尺寸。
这回答了我最初的问题。第二个问题是为什么约束条件不能满足?单元格的固有高度应该与UIView-Encapsulated-Layout-Height
。再说一次,我不确定,但我怀疑这是一个舍入误差(即固有高度达到 200.1 像素,UIView-Encapsulated-Layout-Height
也许四舍五入到 200。我想出的解决方案是降低相关单元格约束的优先级,以允许UIView-Encapsulated-Layout-Height
拥有最后的发言权。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)