iOS开发

使用Masonry自动布局遇到“Unable to simult

2017-07-24  本文已影响2589人  启发禅悟

在使用第三方库ZLSwipeableView的时候,在定义的card view的时候使用的是Masonry来自动布局,结果就发现,对每一个定义在card view内部,使用Marsonry布局的空间,都出现了如下的警告:

[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.

找了很久,都没有找到第二个约束是在哪里设置的,如果有人知道的话,请留言指教。

至于解决方案,就是对card view内部使用Masonry布局的空间添加布局优先级,就可以移除这些警告了。
例如:

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

修改为:

    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).priorityHigh();
    }];
上一篇下一篇

猜你喜欢

热点阅读