Masory添加视图约束时, 报错A multiplier of 0 or a nil second item together with a location for the first attri

1, 错误提示:

A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.’

在使用Masory约束ImageView的frame时出现上述错误.

查询原因, A multiplier of 0 or a nil second item together 也说明当前view为空, 查看代码之后发现.

[_bgImageV mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(@(0));
    make.top.equalTo(@(0));
    make.width.equalTo(@(SCREEN_WIDTH));
    make.height.equalTo(@(kBaseLine(280) ));
}];
[self.view addSubview:_bgImageV];

错误的原因在于, 先约束了frame, 然后再去添加该视图,导致提示view不存在.

修改:
(换一下位置即可)

 [self.view addSubview:_bgImageV];
 [_bgImageV mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(@(0));
    make.top.equalTo(@(0));
    make.width.equalTo(@(SCREEN_WIDTH));
    make.height.equalTo(@(kBaseLine(280) ));
}];

猜你喜欢

转载自blog.csdn.net/xNickname666/article/details/82144702