NSInvalidArgumentException

NSInvalidArgumentException

我以编程方式实现了自动版式。

self.rightSideLine = [[UIView alloc] init];
self.rightSideLine.backgroundColor = COLOR_MojorColor_Depper;
[self.rightSideLine setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:self.rightSideLine];
[self addConstraintToRightSideLine];

addConstraint方法:
- (void)addConstraintToRightSideLine
{
NSLayoutConstraint *constraintToAnimate1 = [NSLayoutConstraint constraintWithItem:self.rightSideLine
                                                                        attribute:NSLayoutAttributeTop
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:self.view
                                                                        attribute:NSLayoutAttributeBottom
                                                                       multiplier:0.00
                                                                         constant:0.0];
[self.view addConstraint:constraintToAnimate1];



NSLayoutConstraint *constraintToAnimate2 = [NSLayoutConstraint constraintWithItem:self.rightSideLine
                                                                        attribute:NSLayoutAttributeLeft
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:self.view
                                                                        attribute:NSLayoutAttributeRight
                                                                       multiplier:1.00
                                                                         constant:-IPAD];
[self.view addConstraint:constraintToAnimate2];





NSLayoutConstraint *constraintToAnimate3 = [NSLayoutConstraint constraintWithItem:self.rightSideLine
                                                                        attribute:NSLayoutAttributeWidth
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:self.view
                                                                        attribute:NSLayoutAttributeWidth
                                                                       multiplier:0.00
                                                                         constant:IPAD];
[self.view addConstraint:constraintToAnimate3];

NSLayoutConstraint *constraintToAnimate4 = [NSLayoutConstraint constraintWithItem:self.rightSideLine
                                                                        attribute:NSLayoutAttributeHeight
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:self.view
                                                                        attribute:NSLayoutAttributeHeight
                                                                       multiplier:1.00
                                                                         constant:0.0];
[self.view addConstraint:constraintToAnimate4];
}

这段代码可以在设备上完美地运行,但是当我运行它离子模拟器时,我得到了NSInvalidArgumentException:

原因:'*** + [NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]:乘数为0或第二个项目的值为零,以及第一个属性的位置会创建一个非法约束,该约束等于恒定。位置属性必须成对指定

最佳答案

您的乘数不能是0.0。它必须> 0

关于ios - 以编程方式实现自动布局时,iOS获取NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30298055/

10-11 18:37