[LayoutConstraints] Unable to simultaneously satisfy constraints.

[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. 
    (
    ,
    ,
    ,
)

代码如上。原因是在设定了子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);;
}

你可能感兴趣的:([LayoutConstraints] Unable to simultaneously satisfy constraints.)