ios使用Masonry布局时解决控制台输出的警告?

代码适配,Masonry一般是首选的。项目中tableview使用最多,那么肯定少不了自定义的cell和view,这就牵涉到控件的布局。

使用过Masonry的都知道,有的时候控制台会输出很多警告,但是布局是正常的,这是为什么呢?

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:0x6180000ae280 UIImageView:0x7faae702cc50.left == XBMixButton:0x7faae702c830.left>,
	<MASLayoutConstraint:0x6180000ae3a0 UIImageView:0x7faae702cc50.width == XBMixButton:0x7faae702c830.height>,
	<MASLayoutConstraint:0x6180000b2360 XBMixButton:0x7faae702de30.width == 80>,
	<MASLayoutConstraint:0x6180000b23c0 XBMixButton:0x7faae702de30.height == 15>,
	<MASLayoutConstraint:0x6000000ab760 XBMixButton:0x7faae702c830.width == XBMixButton:0x7faae702de30.width>,
	<MASLayoutConstraint:0x6000000abfa0 XBMixButton:0x7faae702c830.height == XBMixButton:0x7faae702de30.height>,
	<NSLayoutConstraint:0x61800008f550 UIImageView:0x7faae702cc50.centerX == XBMixButton:0x7faae702c830.centerX>,
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x61800008f550 UIImageView:0x7faae702cc50.centerX == XBMixButton:0x7faae702c830.centerX>

从输出的信息可以知道,有的控件的约束明显重复了设置,所以指出了是哪个控件,重复设置了哪些约束等等。。。。

 

 

Masonry可以设置约束的优先级,优先级分为priorityHigh,priorityMedium,priorityLow(高,中等,低)三个等级。优先级默认为中等,所以当我们对某一个控件的约束条件重复后,会打印警告信息,告诉我们应该去修复它们。

 

既然知道了警告的产生原因,那么解决办法有两种:

1.找到该控件,修改它的相关约束,以消除警告信息。

2.将控件的约束优先级置为高级,那么就算约束重复了也不会有警告。这也是最简单省事的办法。

附上处理方法:

[self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(ws).offset(SPACE).priorityHigh();
    make.top.mas_equalTo(ws).offset(SPACE).priorityHigh();
    make.bottom.mas_equalTo(ws).offset(-SPACE).priorityHigh();
    make.width.mas_equalTo(ws.mas_height).priorityHigh();
}];

哪里有警告就改哪里 。
 

 

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值