Xcode中的限制条件变灰了

6
我正在尝试调试和理解自动布局约束,我注意到在使用xcode(使用酷炫的图层工具)调试视图时,我注意到一个元素的约束如下所示,并且视图确实忽略了这些约束。
所有约束都具有相同的优先级(1000),因为我想要它们全部。所有约束均是通过接口构建器而非代码创建的,在IB中没有警告或冲突。
但是在运行时,我确实看到了这个:
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:0x79684f10 V:[UIImageView:0x79686800(>=160)]>",
    "<NSLayoutConstraint:0x7968a310 V:[UIImageView:0x79686800]-(130.5)-|   (Names: '|':UIView:0x79686790 )>",
    "<NSLayoutConstraint:0x7968a340 V:|-(0)-[UIImageView:0x79686800]   (Names: '|':UIView:0x79686790 )>",
    "<NSLayoutConstraint:0x796997b0 'UIView-Encapsulated-Layout-Height' V:[CoverCell:0x79686570(192)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x7969cd30 h=-&- v=-&- UIView:0x79686790.height == CoverCell:0x79686570.height>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x79684f10 V:[UIImageView:0x79686800(>=160)]>

因此我理解到某些规则存在冲突,但我不确定如何读取此信息。UIImageView上的“>=160”是一个规则,因此它的高度至少为160,而130.5是图像视图的底部填充(因此在使用“systemLayoutSizeFittingSize:UILayoutFittingCompressedSize”时,高度不会为0。因此整个单元格的最小高度为160+130.5)。我不理解错误的其余部分。约束出了什么问题,为什么约束冲突会在运行时发生而不是在IB中发生?
2个回答

6

XCode 6现在支持不同的布局。例如,在紧凑宽度|任何高度布局中存在这些灰色的约束条件,但您当前正在编辑的是任何宽度|任何高度布局。

更详细信息请参见: Storyboard View Elements Greyed Out


1
这取决于情况。如果您没有使用尺寸类,则灰色的是需要删除的。而且您需要再次删除它们。不论听起来多么愚蠢。
如果您使用了尺寸类,那么这意味着您当前的尺寸类与灰色约束的尺寸类不同。(然而第一种情况也可能发生……)
在您的情况下,看起来是第一种情况。您需要再次删除灰色的约束。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接