iOS仅限模拟器中的约束错误

时间:2015-05-19 05:40:35

标签: ios xcode

我使用Xcode Storyboard设计了我的iOS应用程序UI,现在一切看起来都很好,没有警报。

当我在模拟器中运行我的应用程序时,会得到Unable to simultaneously satisfy constraints的列表。这个清单很模糊。

    "<NSLayoutConstraint:0x7b617600 UIButton:0x7b6112f0.width == UIButton:0x7b6112f0.height>",
    "<NSLayoutConstraint:0x7b7abd20 UIButton:0x7b7a3180.centerY == UIButton:0x7b79d0f0.centerY>",
    "<NSLayoutConstraint:0x7b7abd50 UIButton:0x7b7a3180.width == UIButton:0x7b6112f0.width>",
    "<NSLayoutConstraint:0x7b7abd80 UIButton:0x7b7a3180.height == UIButton:0x7b6112f0.height>",
    "<NSLayoutConstraint:0x7b7abdb0 UIButton:0x7b7a3180.centerX == UIButton:0x7b770ec0.centerX>",
    "<NSLayoutConstraint:0x7b7abde0 V:[UIButton:0x7b7a3180]-(2)-[UIButton:0x7b770ec0]>",
    "<NSLayoutConstraint:0x7b7abe30 H:|-(0)-[UIButton:0x7b770ec0]   (Names: '|':UIView:0x7b7abbf0 )>",
    "<NSLayoutConstraint:0x7b7abe60 UIButton:0x7b79d0f0.centerY == UIButton:0x7b78ff40.centerY>",
    "<NSLayoutConstraint:0x7b7abec0 H:[UIButton:0x7b7a3180]-(NSSpace(8))-[UIButton:0x7b79d0f0](LTR)>",
    "<NSLayoutConstraint:0x7b7abf20 UIButton:0x7b79d0f0.width == UIButton:0x7b6112f0.width>",
    "<NSLayoutConstraint:0x7b7abf50 UIButton:0x7b6112f0.height == UIButton:0x7b770ec0.height>",
    "<NSLayoutConstraint:0x7b7abf80 UIButton:0x7b6112f0.height == UIButton:0x7b78ff40.height>",
    "<NSLayoutConstraint:0x7b7abfb0 UIButton:0x7b6112f0.centerY == UIButton:0x7b770ec0.centerY>",
    "<NSLayoutConstraint:0x7b7abfe0 UIButton:0x7b6112f0.width == UIButton:0x7b78ff40.width>",
    "<NSLayoutConstraint:0x7b7ac010 UIButton:0x7b6112f0.width == UIButton:0x7b770ec0.width>",
    "<NSLayoutConstraint:0x7b7ac040 V:|-(2)-[UIButton:0x7b78ff40]   (Names: '|':UIView:0x7b7abbf0 )>",
    "<NSLayoutConstraint:0x7b7ac070 H:[UIButton:0x7b79d0f0]-(NSSpace(8))-[UIButton:0x7b78ff40](LTR)>",
    "<NSLayoutConstraint:0x7b7ac0a0 H:[UIButton:0x7b78ff40]-(0)-|(LTR)   (Names: '|':UIView:0x7b7abbf0 )>",
    "<NSLayoutConstraint:0x7b7ac0d0 UIButton:0x7b60d210.height == UIButton:0x7b6112f0.height>",
    "<NSLayoutConstraint:0x7b7ac100 UIButton:0x7b60d210.centerY == UIButton:0x7b6112f0.centerY>",
    "<NSLayoutConstraint:0x7b7ac130 UIButton:0x7b60d210.bottom == UIView:0x7b7abbf0.bottom>",
    "<NSLayoutConstraint:0x7b7ac390 V:[UIView:0x7b7abb60(<=190)]>",
    "<NSLayoutConstraint:0x7b7ac3c0 H:[UIView:0x7b7abbf0]-(4)-|(LTR)   (Names: '|':UIView:0x7b7abb60 )>",
    "<NSLayoutConstraint:0x7b7ac420 UIView:0x7b7abb60.centerX == UIView:0x7b7abbf0.centerX>",
    "<NSLayoutConstraint:0x7b7ac450 V:[UIView:0x7b7abbf0]-(>=2)-|   (Names: '|':UIView:0x7b7abb60 )>",
    "<NSLayoutConstraint:0x7b7ac4b0 UIView:0x7b7abb60.centerY == UIView:0x7b7abbf0.centerY>",
    "<NSLayoutConstraint:0x7b7bce60 H:[UIView:0x7b7abb60]-(0)-|(LTR)   (Names: '|':UIView:0x7b7a9640 )>",
    "<NSLayoutConstraint:0x7b7bce90 H:|-(0)-[UIView:0x7b7abb60](LTR)   (Names: '|':UIView:0x7b7a9640 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7bfa9e30 h=--& v=--& H:[UIView:0x7b7a9640(320)]>"

这是哪个按钮:UIButton:0x7b6112f0

这是哪个约束:NSLayoutConstraint:0x7b7bce90

在Xcode中Identity inspector我找到了一个标签字段,我标记了所有按钮。但是当在模拟器中运行时,这些标签没有任何好处。

如何识别此输出中的对象?

2 个答案:

答案 0 :(得分:3)

您添加了太多限制并需要重复。您应该避免添加重复的约束。

答案 1 :(得分:0)

如果IB中没有显示警告/冲突,可能是由于NSAutoresizingMaskLayoutConstraintAutoresizingMask是在引入AutoLayout之前主要使用的内容。摆脱它,然后再试一次。

找到列表最后一行的UIView对象并应用:

view.translatesAutoresizingMaskIntoConstraints = NO;

来自Apple Documentation

  

因为自动调整遮罩自然会产生完全指定视图位置的约束,所以必须将要应用更灵活约束的任何视图设置为使用此方法忽略其自动调整遮罩。您应该自己为编程创建的视图调用此方法。使用允许设置约束的工具创建的视图应该已经具有此设置。