簡體   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