2
votes

I implemented Auto Layout programmatically.

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

addConstraint Method:

- (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];
}

This code works perfectly on device, but when I run it ion simulator, I got NSInvalidArgumentException :

reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: 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'

1

1 Answers

0
votes

Your multiplier can't be 0.0. it must be > 0