V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lisonfan
V2EX  ›  iOS

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

  •  
  •   lisonfan · 2018-06-11 23:14:56 +08:00 · 2657 次点击
    这是一个创建于 2350 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    我的代码:

        [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.
    
    zjaihm
        1
    zjaihm  
       2018-06-12 10:09:20 +08:00
    你试一下 make.height.offset(0.5);设置 priority(小于 1000)
    lisonfan
        2
    lisonfan  
    OP
       2018-06-12 10:43:40 +08:00
    @zjaihm #1 嗯,后来昨天晚上我根据 log 的提示降权就没报冲突了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   868 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:04 · PVG 06:04 · LAX 14:04 · JFK 17:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.