2014-09-28 140 views
0

我是新来的自动布局。有人可以解释为什么这不起作用吗? MAFeedbackCell是两个标签的容器。容器中还有其他标签,但这两个:0xaa3aca00x14395240是有冲突的。iOS AutoLayout约束

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)]>" 

回答

5

你有MAFeedbackCell上海华和两个UILabel子视图。

左标签(0xaa3aca0)被约束为不超过八分之一一样宽的上海华:

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

(注意,0.125 = 1/8)

左标签( 0xaa3aca0)和右标签(0x14395240)被约束为具有相同的宽度彼此:

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

所以右视野也必须是不超过总监的八分之一。

左侧的标签的左边缘被约束在上海华盈的左边缘内的一个观点:

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 < =(3 + 2 * L)/ 8。将其简化为L < = 1/2。所以我们可以满足所有这些限制......如果每个标签不超过半点宽。这就要求超级观点不超过四点。

不幸的是你的,上海华被限制为231点宽:

H:[MAFeedbackCell:0x14394d90(231)] 

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

+0

谢谢您的详细解答! – marosoaie 2014-09-28 06:00:37

+0

真棒解释。这一直是Android比iOS更“容易”的地方!嘿! – Fattie 2014-09-28 06:49:30