以编程方式实现自动布局时,iOS获得NSInvalidArgumentException

时间:2015-05-18 08:10:01

标签: ios xcode autolayout

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

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或零第二项以及第一个属性的位置创建一个位置的非法约束等于常数。必须成对指定位置属性'

1 个答案:

答案 0 :(得分:0)

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