简体   繁体   English

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

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

I am trying to fix these errors I keep getting when running my app. 我正在尝试修复运行我的应用程序时不断出现的这些错误。

I have a UITableView that uses prototype cells and I keep getting these errors despite having no errors listed in Xcode Storyboard for constraint problems. 我有一个使用原型单元的UITableView,尽管在Xcode Storyboard中没有列出约束问题的错误,但我仍然遇到这些错误。 Not sure how to read most of these errors so was hoping someone could assist me? 不知道如何阅读大多数这些错误,是否希望有人可以帮助我?

Background UIImageView that should stretch entire cell width/height: 应该伸展整个单元格宽度/高度的背景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) that are suppose to be matching width/height, centered on 3rd UIImageView in cell and equal distances apart from each other (when rotated to landscape, these items stay centered and the distance from left/right on first/last cell just increases): 假设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)]>"
)

Background UIImageView that should stretch entire cell width/height: 应该伸展整个单元格宽度/高度的背景UIImageView:

You want the image view to stretch the entire cell, but you have a rule UIImageView:0x1741e7100.width == 2.5*UIImageView:0x1741e7100.height that locks the aspect ratio at 1:2.5. 您希望图像视图拉伸整个单元格,但是您有一个规则UIImageView:0x1741e7100.width == 2.5*UIImageView:0x1741e7100.height将宽高比锁定为1:2.5。 You need to remove this rule. 您需要删除此规则。

UIImageViews (5) that are suppose to be matching width/height, centered on 3rd UIImageView in cell and equal distances apart from each other (when rotated to landscape, these items stay centered and the distance from left/right on first/last cell just increases): 假设UIImageViews(5)的宽度/高度匹配,位于单元格中第三个UIImageView的中心,并且彼此等距(当旋转到横向时,这些项目保持居中,而第一个/最后一个单元格与左/右的距离只是增加):

This one is much more complex, but I will hazard a guess that it's the same aspect ratio problem. 这要复杂得多,但我会冒险猜测这是相同的纵横比问题。 This time is Bobblehead_TV.BobbleheadImageView:0x100715ff0.width == 0.5*Bobblehead_TV.BobbleheadImageView:0x100715ff0.height which locks the aspect ratio at 1:0.5. 这次是Bobblehead_TV.BobbleheadImageView:0x100715ff0.width == 0.5*Bobblehead_TV.BobbleheadImageView:0x100715ff0.height将宽高比锁定为1:0.5。

My Friend, 我的朋友,

Reasons could be 1: You have insufficient constraints to satisfy the layout. 原因可能是1:您没有足够的约束来满足布局。 or 2: You have added more than the required constraints. 或2:您添加的内容超出了所需的限制。

As a result of which layout is ambiguous. 结果是哪个布局不明确。 It is confused and so warning . 这很困惑,所以很警告。

My opinion is to recheck all your constraints. 我的观点是重新检查您的所有约束。 And provide minimal constraints but be specific. 并提供最少的约束,但要具体。 Thanks 谢谢

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

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