使用Masonry自動布局遇到“Unable to simultaneously satisfy constraints”問題

在使用第三方庫ZLSwipeableView的時候,在定義的card view的時候使用的是Masonry來自動布局,結(jié)果就發(fā)現(xiàn),對每一個定義在card view內(nèi)部,使用Marsonry布局的空間,都出現(xiàn)了如下的警告:

[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:0x6080000bd8e0 UILabel:0x7fabebd48250.width == 199>",
    "<MASLayoutConstraint:0x6000002a8b80 UILabel:0x7fabebd48250.width == 208.687>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x6000002a8b80 UILabel:0x7fabebd48250.width == 208.687>

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

找了很久,都沒有找到第二個約束是在哪里設(shè)置的,如果有人知道的話,請留言指教。

至于解決方案,就是對card view內(nèi)部使用Masonry布局的空間添加布局優(yōu)先級,就可以移除這些警告了。
例如:

    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];

修改為:

    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).priorityHigh();
    }];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容