在使用Masonry布局框架时,有时候因为使用不当会导致约束冲突,会在控制台输出类似这样的警告
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
这类输出很烦,少的话可以设置约束优先级来解决,多的话不想解决怎办?
在网上找到了这个方法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"];
可以设置该参数达到屏蔽的目的,不过警告能解决就解决吧。