使用Masonry自动布局遇到“Unable to simultaneously satisfy constraints”问题

释放双眼,带上耳机,听听看~!

在使用第三方库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();
    }];

 

人已赞赏
iOS文章

iOS TableViewCell注册以及我遇到的一些简单的坑

2019-10-5 10:28:09

iOS文章

iOS中播放gif动态图的方式探讨

2019-10-5 11:11:07

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索