Masonry小技巧

当你写了一个错误的constanints,例如:

[self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(15.0f);
make.left.equalTo(self.contentView).offset(10.f);
make.height.equalTo(10);
make.bottom.equalTo(self.contentView);
}];

然后在你会看到如下的debug log:

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)
(
"",
"",
"",
""
)
Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.

是不是会眼花,如果有很多label你是不是需要找半天。
现在你只需要加上一句

self.statusLabel = [UILabel new];
[self.contentView addSubview:self.statusLabel];
MASAttachKeys(self.statusLabel);

只要加一句,不需要¥998

然后log会变成这样

(
"",
"",
"",
""
)
Will attempt to recover by breaking constraint

是不是很清楚,一看就知道错在哪里。

同理,如果你没有用Masonry,而只是用系统的autolayout API,可以试试NSLayoutConstraint的identifier来让你的debug log更易读。

你可能感兴趣的:(Masonry小技巧)