iOS - 自动布局 'Unable to simultaneously satisfy constraints'



我正在尝试修复运行应用程序时不断遇到的这些错误。

我有一个使用原型单元格的 UITableView,尽管 Xcode 故事板中没有列出约束问题的错误,但我不断收到这些错误。不确定如何阅读这些错误中的大多数,所以希望有人可以帮助我?

应拉伸整个单元格宽度/高度的背景 UIImage视图:

(
    "<NSLayoutConstraint:0x174086c20 UIImageView:0x1741e7100.width == 2.5*UIImageView:0x1741e7100.height>",
    "<NSLayoutConstraint:0x174087530 H:|-(0)-[UIImageView:0x1741e7100]   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x1740875d0 V:[UIImageView:0x1741e7100]-(0)-|   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x174087620 H:[UIImageView:0x1741e7100]-(0)-|   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x174087670 V:|-(0)-[UIImageView:0x1741e7100]   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x170088890 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x174181e10(375)]>",
    "<NSLayoutConstraint:0x1700888e0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x174181e10(160)]>"
)

UIImageViews (5),假定宽度/高度匹配,以单元格中的第三个 UIImageView 为中心,彼此之间的距离相等(当旋转到横向时,这些项目保持居中,并且第一个/最后一个单元格上与左/右的距离只是增加):

(
    "<NSLayoutConstraint:0x174086e00 Bobblehead_TV.BobbleheadImageView:0x100715ff0.width == 0.5*Bobblehead_TV.BobbleheadImageView:0x100715ff0.height>",
    "<NSLayoutConstraint:0x1740873a0 Bobblehead_TV.BobbleheadImageView:0x100715ff0.width == Bobblehead_TV.BobbleheadImageView:0x1007180e0.width>",
    "<NSLayoutConstraint:0x1740873f0 H:|-(0)-[Bobblehead_TV.BobbleheadImageView:0x100715ff0]   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x174087490 Bobblehead_TV.BobbleheadImageView:0x100715ff0.top == UIImageView:0x1741e7100.top>",
    "<NSLayoutConstraint:0x1740874e0 Bobblehead_TV.BobbleheadImageView:0x100715ff0.bottom == UIImageView:0x1741e7100.bottom>",
    "<NSLayoutConstraint:0x1740875d0 V:[UIImageView:0x1741e7100]-(0)-|   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x174087670 V:|-(0)-[UIImageView:0x1741e7100]   (Names: '|':UITableViewCellContentView:0x174181e10 )>",
    "<NSLayoutConstraint:0x174087710 Bobblehead_TV.BobbleheadImageView:0x1007207d0.width == Bobblehead_TV.BobbleheadImageView:0x1007180e0.width>",
    "<NSLayoutConstraint:0x174087800 H:[Bobblehead_TV.BobbleheadImageView:0x100715ff0]-(>=0)-[Bobblehead_TV.BobbleheadImageView:0x1007207d0]>",
    "<NSLayoutConstraint:0x174087850 UITableViewCellContentView:0x174181e10.centerX == Bobblehead_TV.BobbleheadImageView:0x1007180e0.centerX>",
    "<NSLayoutConstraint:0x1740878a0 H:[Bobblehead_TV.BobbleheadImageView:0x1007207d0]-(>=0)-[Bobblehead_TV.BobbleheadImageView:0x1007180e0]>",
    "<NSLayoutConstraint:0x170088890 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x174181e10(375)]>",
    "<NSLayoutConstraint:0x1700888e0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x174181e10(160)]>"
)

应拉伸整个单元格宽度/高度的背景 UIImage视图:

您希望图像视图拉伸整个单元格,但您有一个规则UIImageView:0x1741e7100.width == 2.5*UIImageView:0x1741e7100.height将纵横比锁定在 1:2.5。您需要删除此规则。

UIImageViews (5),假定宽度/高度匹配,以单元格中的第三个 UIImageView 为中心,彼此之间的距离相等(当旋转到横向时,这些项目保持居中,并且第一个/最后一个单元格上与左/右的距离只是增加):

这个要复杂得多,但我可能会猜测这是相同的纵横比问题。这个时间是Bobblehead_TV.BobbleheadImageView:0x100715ff0.width == 0.5*Bobblehead_TV.BobbleheadImageView:0x100715ff0.height,它将纵横比锁定在 1:0.5。

我的朋友,

原因可能是1:您没有足够的约束来满足布局。或2:您添加的约束超过了所需的约束。

因此,布局是模棱两可的。这是混乱的,所以警告.

我的意见是重新检查您的所有限制。并提供最少的约束,但要具体。谢谢

相关内容

最新更新