最近换了新的项目组,而后这个项目组是纯代码,而后我就开始试着用代码去写适配,结果学艺不精,遇到个闪退,搜了一下发现几乎没有人遇到这个问题,后来发现其实就是我本身太粗心了。app
我是这样写的spa
NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hPadding-[_productNewLabel(==13)]" options:0 metrics:nil views:@{@"_productNewLabel":_productNewLabel,@"hPadding":@(hPadding)}];
报错信息是这样的3d
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: It's not possible to set a space equal to the width or height of a view. Perhaps you want to use a view as a spacer?code
其实报错信息说的很明白,就是我写了一个动态的间距hpadding,而后他没识别;orm
看到这不少大神应该都明白了,由于我把hpaddingKeyValue加错地方了blog
我加在了Views里面,其实应该加在metrics就对啦,仍是stackoverflow比较强大呀。最后在里面搜到的答案it
NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hPadding-[_productNewLabel(==13)]" options:0 metrics:@{@"hPadding":@(hPadding)} views:@{@"_productNewLabel":_productNewLabel}];
以上就对啦。io