iOS AutoLayout约束

时间:2014-09-28 05:43:27

标签: ios autolayout

我是autolayout的新手。有人可以解释为什么这不起作用? MAFeedbackCell是两个标签的容器。容器中还有其他标签,但这两个标签:0xaa3aca00x14395240是有冲突的标签。

2014-09-28 08:38:26.056 beats[1052:60b] 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:0xaa3aea0 UILabel:0xaa3aca0.width <= 0.125*MAFeedbackCell:0x14394d90.width>",
    "<NSLayoutConstraint:0xa657130 H:|-(1)-[UILabel:0xaa3aca0](LTR)   (Names: '|':MAFeedbackCell:0x14394d90 )>",
    "<NSLayoutConstraint:0x143955c0 H:[UILabel:0xaa3aca0]-(1)-[UILabel:0x14395240](LTR)>",
    "<NSLayoutConstraint:0x143959c0 UILabel:0x14395240.width == UILabel:0xaa3aca0.width>",
    "<NSLayoutConstraint:0xa558fc0 UILabel:0x14395240.right == MAFeedbackCell:0x14394d90.right - 1>",
    "<NSLayoutConstraint:0xa541660 'UIView-Encapsulated-Layout-Width' H:[MAFeedbackCell:0x14394d90(231)]>"

1 个答案:

答案 0 :(得分:5)

您拥有MAFeedbackCell超级浏览量和两个UILabel子视图。

左侧标签(0xaa3aca0)被限制为不超过超级视图的八分之一:

UILabel:0xaa3aca0.width <= 0.125*MAFeedbackCell:0x14394d90.width

(注意0.125 = 1/8。)

左侧标签(0xaa3aca0)和右侧标签(0x14395240)被限制为具有相同的宽度:

UILabel:0x14395240.width == UILabel:0xaa3aca0.width

因此,正确的视图也必须不超过superview的八分之一。

左侧标签的左边缘被限制为超视图左边缘内的一个点:

H:|-(1)-[UILabel:0xaa3aca0](LTR)   (Names: '|':MAFeedbackCell:0x14394d90 )

右侧标签的右边缘被限制为超视图右边缘内的一个点:

UILabel:0x14395240.right == MAFeedbackCell:0x14394d90.right - 1

这两个标签被约束为一个点分开:

H:[UILabel:0xaa3aca0]-(1)-[UILabel:0x14395240](LTR)

因此,我们假设L是每个标签的宽度,M是超视图的宽度。

这些约束要求1 + L + 1 + L + 1 == M,并且L <= M / 8。

将第一个等式简化为3 + 2 * L == M并代入第二个:L&lt; =(3 + 2 * L)/ 8.将其简化为L <= 1/2。所以我们可以满足所有这些约束......如果每个标签不超过半个点宽。这需要超级视图不超过四个点。

不幸的是,超级视图被限制为231分宽:

 H:[MAFeedbackCell:0x14394d90(231)]

因此,你的约束是不可满足的。

相关问题