Masonry错误记录

2018-04-17  本文已影响0人  我一不小心就

约束要素要配对使用例如

self.lanternSwitchBtn = [[UIButton alloc] init];
     [self.lanternSwitchBtn setImage:[UIImage imageNamed:@"ic_shut down"]
     forState:UIControlStateNormal];
     [self addSubview:self.lanternSwitchBtn];
     [self.lanternSwitchBtn makeConstraints:^(MASConstraintMaker *make) {
         make.right.equalTo(self.mas_right).offset(-19.0f);// 要素点
         make.centerY.equalTo(lanternIcon.mas_centerY);
         NSLog(@"width:%f======height:%f",switchImgSize.width,switchImgSize.height);
         make.size.mas_equalTo(CGSizeMake(switchImgSize.width, switchImgSize.height));
     }];

而不能写成

self.lanternSwitchBtn = [[UIButton alloc] init];
     [self.lanternSwitchBtn setImage:[UIImage imageNamed:@"ic_shut down"]
     forState:UIControlStateNormal];
     [self addSubview:self.lanternSwitchBtn];
     [self.lanternSwitchBtn makeConstraints:^(MASConstraintMaker *make) {
         make.right.equalTo(self.mas_trailing).offset(-19.0f);// 要素点
         make.centerY.equalTo(lanternIcon.mas_centerY);
         NSLog(@"width:%f======height:%f",switchImgSize.width,switchImgSize.height);
         make.size.mas_equalTo(CGSizeMake(switchImgSize.width, switchImgSize.height));
     }];

虽然mas_right和mas_trailing要表达的意思是一样的,但是这种不配对的用法会导致崩溃,必须对应使用

上一篇下一篇

猜你喜欢

热点阅读