gpt4 book ai didi

iOS 在以编程方式实现自动布局时获取 NSInvalidArgumentException

转载 作者:行者123 更新时间:2023-12-01 16:33:39 44 4
gpt4 key购买 nike

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

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

这段代码在设备上完美运行,但是当我运行 ionic 模拟器时,我得到了 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'

最佳答案

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

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

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com