0

我有一个UICollectionViewCell自动布局约束。它按方面工作,但我的应用程序打印了很多关于未满足约束的警告:

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:0x7f9e650c50f0 UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top == UIView:0x7f9e650c0fd0.topMargin - 8>",
    "<NSLayoutConstraint:0x7f9e650c51e0 UIView:0x7f9e650c17f0.top == UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top + 20>",
    "<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f9e650d8550 h=--& v=--& V:[UIView:0x7f9e650c0fd0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我尝试了很多不同的组合来找出问题的根源。在使用 Debug View Hierarchy 检查我的视图层次结构时,我发现有一个我没有添加的 UIView 并且这个 UIView 会导致警告消息。 隐藏的 UIView

那么如何才能摆脱这些警告信息呢?

更新

这是我的视图层次结构:

等级制度

看法

4

4 回答 4

1

好的,我在这里找到了答案:UITableViewCell 中 iOS7 上的自动布局约束问题

问题是关于单元格的隐藏内容视图。要消除错误,请在返回单元格之前执行以下操作cellForItemAtIndexPath

cell.contentView.frame = cell.bounds;
cell.contentView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin;
于 2015-02-12T08:18:28.007 回答
0

我认为问题不在于隐藏的视图。UICollectionViewCell有一个像UITableViewCell. 约束冲突似乎在UILabel.

如果您可以截取情节提要的屏幕截图,那就太好了。

于 2015-01-23T19:28:43.920 回答
0

可以从错误中读取发生了什么:您的标签和它下面的 otherView 附加到神秘视图,标签 8 离开顶部,然后 20 将 otherView 分开,8 从 otherView 底部到神秘视图。很标准。但是,autoresizingMask 将神秘视图设置为零高度。由于它不能同时满足两者,它打破了将 otherView 保持在底部的约束。MysteryView 的高度为零(但显然停留在顶部位置),Label 的高度为 8,等等,直到 otherView 挂在底部的任何东西上。

由于神秘视图附加到您的 UILabel 和 otherView,因此应该可以找到它和/或打破约束。找到带有文本“Toz Kat Elek >30”的标签并查看它的 Size Inspector(右侧面板中的标尺图标)。通过 -8 找到附加到其顶部空间的约束。可能不止一个,这将是问题的一部分。双击它,它将在 IB 窗口左侧的 Document Outline 中突出显示,并且约束详细信息将出现在检查器中。

如果您只能找到希望附加到 UILabel 和其他元素的视图,请检查这些视图。您可能希望使用底部的按钮清除所有约束并重新开始。

但是,如果您发现了神秘视图,并且它确实是偷渡者(显然高度为零),则将其删除。附加到您的标签和视图的约束正在工作,因此您可能需要添加新的约束,将顶部和底部附加到真正的顶部和底部超级视图。

于 2015-02-03T23:44:29.753 回答
0

您是否尝试过删除 UIView 的底部边距约束?对于您在警告中发布的内容,它说它正在删除它以从错误中恢复。如果您已经这样做了,您可以发布视图层次结构但打开约束吗?.

于 2015-02-09T01:46:53.480 回答