在使用Masonry布局框架時,有時候因為使用不當(dāng)會導(dǎo)致約束沖突,會在控制臺輸出類似這樣的警告
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-03-12 23:11:35.844573+0800 artDesign[11723:4004040] [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.
(
"<MASLayoutConstraint:0x283438000 UILabel:0x102d8a3d0.height == 43.9659>",
"<MASLayoutConstraint:0x283438360 UILabel:0x102d8a3d0.top == UITableViewCellContentView:0x102d8a1e0.top + 9>",
"<MASLayoutConstraint:0x283435980 UILabel:0x102fbf420.height == 15>",
"<MASLayoutConstraint:0x283435b60 UILabel:0x102fbf420.top == UILabel:0x102d8a3d0.bottom + 10>",
"<MASLayoutConstraint:0x283435c20 UILabel:0x102fbf420.bottom == UITableViewCellContentView:0x102d8a1e0.bottom - 10>",
"<NSLayoutConstraint:0x283336300 UITableViewCellContentView:0x102d8a1e0.height == 88>"
)
Will attempt to recover by breaking constraint
這類輸出很煩,少的話可以設(shè)置約束優(yōu)先級來解決,多的話不想解決怎辦?
在網(wǎng)上找到了這個方法http://landcareweb.com/questions/7235/zai-xcodede-diao-shi-kong-zhi-tai-shu-chu-zhong-jin-yong-zi-dong-bu-ju-yue-shu-cuo-wu-xiao-xi
Swift 3
UserDefaults.standard.setValue(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
Objective-C
[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];
可以設(shè)置該參數(shù)達(dá)到屏蔽的目的,不過警告能解決就解決吧。