Xcode 中的约束变灰
Contraints greyed-out in Xcode
我正在尝试调试+理解自动布局约束,我注意到在使用 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)]>
因此我了解到某些规则存在冲突,但我不确定如何阅读此内容
>=160
是 UIImageView 的规则,因此它的高度至少为 160,而 130.5 是图像视图的底部填充(因此当使用 systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
时,高度不会为 0 .所以整个单元格的最小高度是160+130.5)
其余错误我没看懂
约束有什么问题,为什么约束冲突发生在运行时而不是在 IB 中?
XCode 6 现在支持不同的布局。此灰色约束存在于 Compact Width |例如,任何高度 布局,但您当前正在编辑 任何宽度 |任意高度.
更详细:
Storyboard View Elements Greyed Out
视情况而定。如果您不使用大小 classes,则灰色的是已删除的。你需要第二次删除它们。不管听起来多么愚蠢。
如果您使用尺寸 classes,这意味着您当前的尺寸 class 与灰色约束不同。 (不过第一种情况也是有可能的...)
你的情况看起来像是第一种情况。您需要再次删除灰色约束。
我正在尝试调试+理解自动布局约束,我注意到在使用 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)]>
因此我了解到某些规则存在冲突,但我不确定如何阅读此内容
>=160
是 UIImageView 的规则,因此它的高度至少为 160,而 130.5 是图像视图的底部填充(因此当使用 systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
时,高度不会为 0 .所以整个单元格的最小高度是160+130.5)
其余错误我没看懂
约束有什么问题,为什么约束冲突发生在运行时而不是在 IB 中?
XCode 6 现在支持不同的布局。此灰色约束存在于 Compact Width |例如,任何高度 布局,但您当前正在编辑 任何宽度 |任意高度.
更详细: Storyboard View Elements Greyed Out
视情况而定。如果您不使用大小 classes,则灰色的是已删除的。你需要第二次删除它们。不管听起来多么愚蠢。
如果您使用尺寸 classes,这意味着您当前的尺寸 class 与灰色约束不同。 (不过第一种情况也是有可能的...)
你的情况看起来像是第一种情况。您需要再次删除灰色约束。