转:http://blog.csdn.net/nb_token/article/details/53305414
代码适配,砌体一般是首选的。项目中的tableview使用最多,那么肯定少不了自定义的细胞和视图,这就牵涉到控件的布局。
使用过砌体的都知道,有的时候控制台会输出很多警告,但是布局是正常的,这是为什么呢?
- 以下列表中的至少一个约束可能是您不想要的。
- 尝试 这样:
- (1 )查看每个约束,并 尝试 找出你不期望的;
- (2 )找到添加了不需要的约束或约束的代码并进行修复。
- (
- <MASLayoutConstraint:0 x 6 1 8 0 0 0 0 ae 2 8 0 UIImageView :0 x 7 faae 7 0 2 cc 5 0 .left == XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .left >,
- <MASLayoutConstraint:0 x 6 1 8 0 0 0 0 ae 3 a 0 UIImageView :0 x 7 faae 7 0 2 cc 5 0 .width == XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .height >,
- <MASLayoutConstraint:0 x 6 1 8 0 0 0 0 b 2 3 6 0 XBMixButton :0 x 7 faae 7 0 2 de 3 0 .width == 8 0 >,
- <MASLayoutConstraint:0 x 6 1 8 0 0 0 0 b 2 3 c 0 XBMixButton :0 x 7 faae 7 0 2 de 3 0 .height == 1 5 >,
- <MASLayoutConstraint:0 x 6 0 0 0 0 0 0 ab 7 6 0 XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .width == XBMixButton :0 x 7 faae 7 0 2 de 3 0 .width >,
- <MASLayoutConstraint:0 x 6 0 0 0 0 0 0 abfa 0 XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .height == XBMixButton :0 x 7 faae 7 0 2 de 3 0 .height >,
- <NSLayoutConstraint:0 x 6 1 8 0 0 0 0 8 f 5 5 0 UIImageView :0 x 7 faae 7 0 2 cc 5 0 .centerX == XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .centerX >,
- )
- 将试图通过破坏约束来恢复
- <NSLayoutConstraint:0 x 6 1 8 0 0 0 0 8 f 5 5 0 UIImageView :0 x 7 faae 7 0 2 cc 5 0 .centerX == XBMixButton :0 x 7 faae 7 0 2 c 8 3 0 .centerX >
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>
从输出的信息可以知道,有的控件的约束明显重复了设置,所以指出了是哪个控件,重复设置了哪些约束等等….
既然知道了警告的产生原因,那么解决办法有两种:
1.找到该控件,修改它的相关约束,以消除警告信息。
2.将控件的约束优先级置为高级,那么就算约束重复了也不会有警告。这也是最简单省事的办法。
附上处理方法:
- [ self .headImageView mas_makeConstraints :^(MASConstraintMaker * make){
- make .left .mas_equalTo (ws).offset (SPACE).priorityHigh ();
- 使.TOP .mas_equalTo (WS).offset (SPACE).priorityHigh ();
- make .bottom .mas_equalTo (ws).offset (-SPACE).priorityHigh ();
- make .width .mas_equalTo (ws .mas_height ).priorityHigh ();
- }];
[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();
}];