繁体   English   中英

iOS-AutoLayout'无法同时满足约束'

[英]iOS - AutoLayout 'Unable to simultaneously satisfy constraints'

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

我有一个使用原型单元的UITableView,尽管在Xcode Storyboard中没有列出约束问题的错误,但我仍然遇到这些错误。 不知道如何阅读大多数这些错误,是否希望有人可以帮助我?

应该伸展整个单元格宽度/高度的背景UIImageView:

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

应该伸展整个单元格宽度/高度的背景UIImageView:

您希望图像视图拉伸整个单元格,但是您有一个规则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:您添加的内容超出了所需的限制。

结果是哪个布局不明确。 这很困惑,所以很警告。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM