请教一个关于 Masonry 布局约束冲突的问题

2018-06-11 23:14:56 +08:00
 lisonfan

从上到下从左到右,我看上去看觉没问题,但是约束还是冲突了

我的代码:

    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(36, 36));
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(14);
    }];
    
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.avatarImageView.mas_right).offset(12);
        make.right.equalTo(self.contentView).offset(-16);
        make.top.equalTo(self.avatarImageView.mas_top);
    }];
    
    [self.commentContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userNameLabel.mas_bottom).offset(10);
        make.left.equalTo(self.userNameLabel.mas_left);
        make.right.equalTo(self.contentView).offset(-16);
    }];
    
    [self.newsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.commentContentLabel.mas_bottom).offset(15);
        make.left.equalTo(self.commentContentLabel.mas_left);
        make.right.equalTo(self.contentView).offset(-16);
    }];
    
    [self.commentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.newsTitleLabel.mas_left);
        make.top.equalTo(self.newsTitleLabel.mas_bottom).offset(10);
    }];
    
    [self.goodView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(50, 50));
        make.centerY.equalTo(self.commentTimeLabel);
        make.right.equalTo(self.newsTitleLabel.mas_right);
    }];
    
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.commentTimeLabel.mas_bottom).offset(8);
        make.left.equalTo(self.commentTimeLabel.mas_left);
        make.right.equalTo(self.contentView);
        make.height.offset(0.5);
        make.bottom.equalTo(self.contentView);
    }];

Log:

2018-06-11 23:08:46.334734+0800 [55085:3302437] [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:0x6040002b7760 UIImageView:self.avatarImageView.top == UITableViewCellContentView:0x7fe2ff295f10.top + 14>",
    "<MASLayoutConstraint:0x6040002b8720 UILabel:self.userNameLabel.top == UIImageView:self.avatarImageView.top>",
    "<MASLayoutConstraint:0x6040002b6980 UILabel:self.commentContentLabel.top == UILabel:self.userNameLabel.bottom + 10>",
    "<MASLayoutConstraint:0x6040002bb1e0 WXMyCommentCustomLabel:self.newsTitleLabel.top == UILabel:self.commentContentLabel.bottom + 15>",
    "<MASLayoutConstraint:0x6040002ba340 UILabel:self.commentTimeLabel.top == WXMyCommentCustomLabel:self.newsTitleLabel.bottom + 10>",
    "<MASLayoutConstraint:0x6040002b6380 UILabel:self.lineLabel.top == UILabel:self.commentTimeLabel.bottom + 8>",
    "<MASLayoutConstraint:0x6040002b71c0 UILabel:self.lineLabel.height == 0.5>",
    "<MASLayoutConstraint:0x6040002b6b60 UILabel:self.lineLabel.bottom == UITableViewCellContentView:0x7fe2ff295f10.bottom>",
    "<NSLayoutConstraint:0x604000686130 UITableViewCellContentView:0x7fe2ff295f10.height == 43.5>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x6040002b71c0 UILabel:self.lineLabel.height == 0.5>

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.
2018-06-11 23:08:46.335202+0800 [55085:3302437] [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:0x6040002b7760 UIImageView:self.avatarImageView.top == UITableViewCellContentView:0x7fe2ff295f10.top + 14>",
    "<MASLayoutConstraint:0x6040002b8720 UILabel:self.userNameLabel.top == UIImageView:self.avatarImageView.top>",
    "<MASLayoutConstraint:0x6040002b6980 UILabel:self.commentContentLabel.top == UILabel:self.userNameLabel.bottom + 10>",
    "<MASLayoutConstraint:0x6040002bb1e0 WXMyCommentCustomLabel:self.newsTitleLabel.top == UILabel:self.commentContentLabel.bottom + 15>",
    "<MASLayoutConstraint:0x6040002ba340 UILabel:self.commentTimeLabel.top == WXMyCommentCustomLabel:self.newsTitleLabel.bottom + 10>",
    "<MASLayoutConstraint:0x6040002b6380 UILabel:self.lineLabel.top == UILabel:self.commentTimeLabel.bottom + 8>",
    "<MASLayoutConstraint:0x6040002b6b60 UILabel:self.lineLabel.bottom == UITableViewCellContentView:0x7fe2ff295f10.bottom>",
    "<NSLayoutConstraint:0x604000686130 UITableViewCellContentView:0x7fe2ff295f10.height == 43.5>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x6040002bb1e0 WXMyCommentCustomLabel:self.newsTitleLabel.top == UILabel:self.commentContentLabel.bottom + 15>

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.
2018-06-11 23:08:46.365781+0800 [55085:3302437] [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:0x6040002b8d20 UIImageView:self.avatarImageView.width == 36>",
    "<MASLayoutConstraint:0x6040002b8a80 UIImageView:self.avatarImageView.left == UITableViewCellContentView:0x7fe2ff295f10.left + 15>",
    "<MASLayoutConstraint:0x6040002b7ac0 UILabel:self.userNameLabel.left == UIImageView:self.avatarImageView.right + 12>",
    "<MASLayoutConstraint:0x6040002bb180 UILabel:self.commentContentLabel.left == UILabel:self.userNameLabel.left>",
    "<MASLayoutConstraint:0x6040002b7a60 WXMyCommentCustomLabel:self.newsTitleLabel.left == UILabel:self.commentContentLabel.left>",
    "<MASLayoutConstraint:0x6040002b9f80 WXMyCommentCustomLabel:self.newsTitleLabel.right == UITableViewCellContentView:0x7fe2ff295f10.right - 16>",
    "<NSLayoutConstraint:0x60400049af90 UITableViewCellContentView:0x7fe2ff295f10.width == 0>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x6040002b8d20 UIImageView:self.avatarImageView.width == 36>

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.
2018-06-11 23:08:46.366501+0800 [55085:3302437] [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:0x6040002b8a80 UIImageView:self.avatarImageView.left == UITableViewCellContentView:0x7fe2ff295f10.left + 15>",
    "<MASLayoutConstraint:0x6040002b7ac0 UILabel:self.userNameLabel.left == UIImageView:self.avatarImageView.right + 12>",
    "<MASLayoutConstraint:0x6040002bb180 UILabel:self.commentContentLabel.left == UILabel:self.userNameLabel.left>",
    "<MASLayoutConstraint:0x6040002b7a60 WXMyCommentCustomLabel:self.newsTitleLabel.left == UILabel:self.commentContentLabel.left>",
    "<MASLayoutConstraint:0x6040002b9f80 WXMyCommentCustomLabel:self.newsTitleLabel.right == UITableViewCellContentView:0x7fe2ff295f10.right - 16>",
    "<NSLayoutConstraint:0x60400049af90 UITableViewCellContentView:0x7fe2ff295f10.width == 0>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x6040002b7ac0 UILabel:self.userNameLabel.left == UIImageView:self.avatarImageView.right + 12>

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.
2588 次点击
所在节点    iOS
2 条回复
zjaihm
2018-06-12 10:09:20 +08:00
你试一下 make.height.offset(0.5);设置 priority(小于 1000)
lisonfan
2018-06-12 10:43:40 +08:00
@zjaihm #1 嗯,后来昨天晚上我根据 log 的提示降权就没报冲突了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/462303

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX