[英]iOS “Unable to simultaneously satisfy constraints”
我將使用以下表示法來解釋已入侵的視圖:
在iPad-Air2模擬器上運行時,我得到以下輸出:
2016-11-03 08:09:07.700117 MyApp[16645:6976134] [LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x60000009d600 h=--& v=--& QuizButtons:0x7fcb8e521830.width == 717 (active)>",
"<NSLayoutConstraint:0x608000281fe0 H:|-(0)-[ImgWhiteBar:0x7fcb8e525020] (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x608000282210 ImgWhiteBar:0x7fcb8e525020.width == 1.07143*QuizButtons:0x7fcb8e521830.width (active)>",
"<NSLayoutConstraint:0x60000009b9e0 'UIView-Encapsulated-Layout-Width' ViewTestVC:0x7fcb8e639b30.width == 768 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
我對記錄的約束的解釋是:
<h=--& v=--&>
,寬度= 717 也許更簡單
問題:
在這里將不勝感激!
編輯
這是三個約束:
沖突約束的列表包括h=--& v=--&
,這是默認的非自動布局形式。
我試圖使用自動布局獲取初始大小和位置,然后嘗試通過設置translatesAutoresizingMaskIntoConstraints = YES來關閉自動布局。 我在Apple開發人員論壇上得到了一個答案,說在這種情況下,我需要刪除視圖的所有約束,可能是通過從超級視圖中刪除並添加回來。
小費
在研究此錯誤時,我發現了一種使約束沖突日志更易於理解的方法。 問題是視圖顯示為匿名,僅指定類而不指定名稱。
為了使您的視圖可識別 ,請打開您的.m
文件之一,並為要標識的每個視圖添加一個新類,如下所示:
@interface ImgWhiteBar: UIImageView
@end
@implementation ImgWhiteBar
@end
@interface Spacer1: UIView
@end
@implementation Spacer1
@end
之后,在InterfaceBuilder中,選擇每個視圖,然后在右側的“ Identity Inspector”中,將通用類(UIVIew,UIImageView等)修改為您剛創建的類之一。
現在再次運行,然后運行Abracadabra-所有視圖現在都通過其自定義類進行標識,從而使您能夠了解那里發生的情況。
享受有趣的調試約束!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.