[aSubView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(10);
make.right.equalTo(self).offset(-10);
}
警告如下:
[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:0x6040002a0000 UILabel:0x7f9a1ee29800.left == PfasDetailInfoView:0x7f9a1ee28bb0.left + 11>,
<MASLayoutConstraint:0x6040002a0180 UILabel:0x7f9a1ee29800.right == PfasDetailInfoView:0x7f9a1ee28bb0.right - 15>,
<NSLayoutConstraint:0x604000286fe0 PfasDetailInfoView:0x7f9a1ee28bb0.width == 0>,
)
代码如上。原因是在设定了子view的left和right后,就隐藏了一个条件:superView的width必须大于等于20,才能满足上面的条件。
但如果上面的代码是放在superView的init中的话,此时superView的约束还没有加上,因为view必须addSubview之后,才能增加约束。此时系统给superView默认加了个width = 0的约束,就和superView的width必须必须大于等于20的条件冲突了。
解决办法:
[aSubView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(10);
make.right.equalTo(self).offset(-10).priority(900);;
}
网友评论