Ios NSLayoutConstraint错误

Ios NSLayoutConstraint错误,ios,objective-c,nslayoutconstraint,Ios,Objective C,Nslayoutconstraint,有人知道怎么解决这个问题吗?我试着按照他们的建议去做,但我所做的一切都不能解决这个问题 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 unw

有人知道怎么解决这个问题吗?我试着按照他们的建议去做,但我所做的一切都不能解决这个问题

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:0xd2af8f0 H:[UIView:0xd2a2530(302)]>",
        "<NSLayoutConstraint:0xd467760 H:[UIView:0xd2a2530]-(9)-|   (Names: '|':UIView:0xd2af800 )>",
        "<NSLayoutConstraint:0xd2afce0 H:|-(400)-[UIView:0xd2a2530]   (Names: '|':UIView:0xd2af800 )>",
        "<NSAutoresizingMaskLayoutConstraint:0x179be3d0 h=--& v=--& H:[UIView:0xd2af800(320)]>"
    )

    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0xd2af8f0 H:[UIView:0xd2a2530(302)]>

让我们重新排列错误中的前三项:

    "<NSLayoutConstraint:0xd2afce0 H:|-(400)-[UIView:0xd2a2530]   (Names: '|':UIView:0xd2af800 )>",
    "<NSLayoutConstraint:0xd2af8f0 H:[UIView:0xd2a2530(302)]>",
    "<NSLayoutConstraint:0xd467760 H:[UIView:0xd2a2530]-(9)-|   (Names: '|':UIView:0xd2af800 )>",
“”,
"",
"",
因此,从superview前缘到后缘有400+302+9==711个空间点。现在:

    "<NSAutoresizingMaskLayoutConstraint:0x179be3d0 h=--& v=--& H:[UIView:0xd2af800(320)]>"
“”
该超级视图被约束为320点宽。711 != 320这就是冲突

superview的
translatesAutoResizengMaskinToConstraints
属性设置为true,这就是最后一个约束的来源。我不确定您尝试了什么,但它没有将该属性设置为false


什么是superview的superview?它是由系统控制的吗?在这种情况下,您将无法清除其
translatesAutoresizingMaskIntoConstraints
属性。相反,您必须使您的约束更加灵活,以应对系统施加的约束。

在我看来,您在故事板中添加了太多的约束。自动布局尝试计算X、Y、宽度和高度。在这种情况下,UIView的高度由两个参数设置:1.)它被约束为302;2.)通过与一些其他视图的顶部/底部分别具有(9)和(400)的垂直间距

案例1是显而易见的。你说,它必须是302高。案例2不那么明显。例如,如果superview的高度为1000 px,则视图的高度必须为591 px(从顶部看为9,从底部看为400…)

因此存在冲突,“自动布局”会将其中一个吹走

修复方法:清除所有约束,然后手动设置或重置为建议值

    "<NSAutoresizingMaskLayoutConstraint:0x179be3d0 h=--& v=--& H:[UIView:0xd2af800(320)]>"