簡體   English   中英

錯誤:無法同時滿足約束

[英]Error: Unable to simultaneously satisfy constraints

我收到此錯誤:

Unable to simultaneously satisfy constraints.
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:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names:    '|':UIView:0x1600a980 )>",
 "<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0]   (Names: '|':UIView:0x1600a980 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>",
"<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names: '|':UIView:0x1600a980    )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in 
<UIKit/UIView.h> may also be helpful.

生成此錯誤的視圖對左/右/上/下有4個約束,我無法刪除它們中的任何一個。

我努力了:

[View setTranslatesAutoresizingMaskIntoConstraints:NO];

沒有結果。

你知道如何解決這個問題嗎?

謝謝!

問題出在垂直布局中。

<NSAutoresizingMaskLayoutConstraint:0x9e2d130 h=--- v=--- V:[UIWindow:0x9e0ea30(480)]>

自動調整窗口的掩碼。 固定邊距和尺寸。 你無法改變這一點。

<NSAutoresizingMaskLayoutConstraint:0x1600e8a0 h=-&- v=-&- UIView:0x1600a980.height == UIWindow:0x9e0ea30.height>

自動化掩碼(固定邊距,可調整大小的內容)。 可能是你的控制器的視圖。 高度為480 (設置為等於窗口的大小)。 這里沒什么好解決的。

<NSLayoutConstraint:0x1600aec0 V:[UIView:0x102021d0]-(0)-|   (Names:    '|':UIView:0x1600a980 )>
<NSLayoutConstraint:0x1600ae80 V:|-(494)-[UIView:0x102021d0]   (Names: '|':UIView:0x1600a980 )>

您可以注意到兩個約束都在使用相同的視圖( [UIView:0x102021d0] )並且具有與參數相同的第二個視圖( UIView:0x1600a980 )。 第二個視圖是我們控制器的視圖。

這兩個約束定義了距第二個視圖邊緣的距離。 第一個定義底部( 0 )。 第二個定義頂部( 494 )。 如果superview的大小為480 ,則表示[UIView:0x102021d0]高度等於-14 ,觸發該異常。

怎么解決? 好吧,將494約束更改為正確的值。 有可能你甚至不想要“頂部”約束,也許你想要一個固定的高度。

問題是怎么出現的? 您可能為iPhone 5創建了約束,然后您嘗試使用iPhone 4運行應用程序。如果您將xib中的模擬大小更改為iPhone 4,則應立即看到問題。

仍然有一些視圖將translatesAutoresizingMaskIntoConstraints設置為YES設置為YES ,否則您將無法獲得該消息。 這可能是視圖的超級視圖,它會給你帶來麻煩。 確保它也不會將其自動調整掩碼轉換為約束。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM