ios - 自动布局 : What creates constraints named UIView-Encapsulated-Layout-Width & Height?

标签 ios uitableview uicollectionview autolayout

我的布局约束在 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-WidthUIView-Encapsulated-Layout-HeightUICollectionView 和 friend 创建,并且存在以强制执行 sizeForItemAtIndexPath 委托(delegate)方法返回的大小。我想这是为了确保 cellForItemAtIndexPath 设置的 UICollectionViewCell 最终达到它被告知的大小。

这回答了我最初的问题。第二个问题是为什么约束不能满足?单元格的固有高度应该与 UIView-Encapsulated-Layout-Height 相同。同样,我不确定,但我怀疑这是一个舍入错误(即固有高度达到 200.1 像素,UIView-Encapsulated-Layout-Height 可能四舍五入到 200。修复我想出的是降低相关单元格约束的优先级,以允许 UIView-Encapsulated-Layout-Height 说了算。

关于ios - 自动布局 : What creates constraints named UIView-Encapsulated-Layout-Width & Height?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23308400/

相关文章:

ios - 如何检查以下响应中是否存在数据 key ?

ios - 检查 AVPlayer 的播放状态

objective-c - 在 UITableView 中加载本地 json 信息

ios - UITableView willSelectRowAtIndexPath 无法更改单元格中的图像

ios - 无法在Xcode6中设置UITableViewCell,因为“自动属性合成不会合成属性..”警告

ios - UICollectionView 的 prepareLayout 和 invalidateLayout

ios - 使用 Photo Kit 和 Swift 在 UICollectionViewCell 中模糊图像

ios - 如何在 Swift 中隐藏 UITableView?

ios - UICollectionview 单元格在滚动时发生变化

ios - Swift Sprite 套件 : How do you set an animation for a random time?