Xcode 中的约束变灰
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28473334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Contraints greyed-out in Xcode
提问by Nick Ginanto
I am trying to debug+understand autolayout constraints and I notice that when debugging the view with xcode (using the cool layer thing) I noticed that on one element in the view the constraints look like this
我正在尝试调试+理解自动布局约束,我注意到在使用 xcode(使用很酷的层)调试视图时,我注意到在视图中的一个元素上,约束看起来像这样
and the view is indeed ignoring these constraints.
并且该视图确实忽略了这些限制。
All constraints have the same priority (1000) since I want them all. All constraints were made with interface builder and not through code, and there are not warning or conflicts in IB.
所有约束都具有相同的优先级(1000),因为我想要它们。所有约束都是通过界面构建器而不是通过代码做出的,并且在 IB 中没有警告或冲突。
But in runtime I do see this
但在运行时我确实看到了这一点
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)]>
So from this I understand that some rules conflict, but I'm not sure how to read this
所以从这里我理解一些规则冲突,但我不知道如何阅读
the >=160
is a rule on the UIImageView so it would have height of atleast 160 and 130.5 is the bottom padding of the imageview (so when using systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
the height won't be 0. So the minimum height for the entire cell is 160+130.5)
这>=160
是 UIImageView 上的规则,因此它的高度至少为 160,而 130.5 是图像视图的底部填充(因此使用systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
高度时不会为 0。因此整个单元格的最小高度为 160+130.5)
The rest of the error I don't understand.
其余的错误我不明白。
What is wrong with the constraints and why do constraint conflicts occur in runtime and not in IB?
约束有什么问题,为什么约束冲突发生在运行时而不是 IB?
回答by orkenstein
XCode6 now supports different layouts. This greyed out constraints exist in Compact Width | Any Heightlayout, for example, but you currently editing Any Width | Any Height.
XCode6 现在支持不同的布局。此灰色约束存在于Compact Width | 例如,任何高度布局,但您当前正在编辑 任何宽度 | 任何高度。
More detailed: Storyboard View Elements Greyed Out
更详细: 故事板视图元素变灰
回答by b.zdybowicz
It depends. If you don't use size classes the grey ones are the removed ones. And you need to remove them second time. No matter how stupid it sounds.
这取决于。如果您不使用尺寸等级,则灰色等级是已删除的等级。你需要第二次删除它们。不管这听起来多么愚蠢。
If you use size classes, it means that your current size class is different than for greyed constraint. (however the first scenario is also possible...)
如果您使用尺寸等级,则意味着您当前的尺寸等级与灰色约束不同。(但是第一种情况也是可能的......)
In your case it looks like this is the first case. You need to remove greyed constraints once again.
在您的情况下,这似乎是第一种情况。您需要再次删除灰色约束。