我的布局约束在Interface Builder中很好,但在运行时会出现异常,这要归功于框架的某些部分应用了我真正不想要的固定高度和宽度约束.它们为什么在那里,以及如何关闭它们?

它们是日志(log)列表中显示的最后两个约束:

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-Height的约束是由UICollectionView和friends创建的,存在这些约束是为了强制执行sizeForItemAtIndexPath委托方法返回的大小.我想这是为了确保cellForItemAtIndexPath设置的UICollectionViewCell最终达到它被告知的大小.

这回答了我最初的问题.第二个问题是,为什么这些限制无法得到满足?该单元的固有高度应与UIView-Encapsulated-Layout-Height相同.同样,我也不确定,但我怀疑这是一个舍入错误(即固有高度为200.1像素,UIView-Encapsulated-Layout-Height可能舍入为200.我提出的解决方案是降低相关单元格约束的优先级,以允许UIView-Encapsulated-Layout-Height拥有最后一个字).

Ios相关问答推荐

Firebase SDK 10+—无法安装软件包

Swift导航远离视频导致崩溃

SwiftData共享扩展阻止应用程序打开SQLite文件

如何链式设置 AttributeContainer 的 UIKit 属性?

Swift Combine:prepend() before share() 阻止初始接收器执行

Flutter IOS 构建错误 - 在签名和功能编辑器中 Select 一个开发团队.

在 iPad 上删除列表的顶部和底部行

分析应用程序版本时出错 - Apple 提交到store

通过按钮打开 AppStore

关闭所有打开的视图控制器的单个函数

在 iOS 7 上更改标签栏色调 colored颜色

标题为 UIImage 的导航栏

Xcode 8:函数类型不能有参数标签 destruct 我的构建

在 iOS 8.1 模拟器上更改语言不起作用

iOS UITextView 或 UILabel 带有可点击的动作链接

什么是强属性属性

检测应用程序何时进入我的视图背景的最佳方法是什么?

Parse for iOS:try 运行应用程序时出错

如何为 NSDate 添加一个月?

我的应用程序因使用广告支持框架而被拒绝.哪个图书馆负责?