【发布时间】:2013-10-25 15:16:09
【问题描述】:
我在一个superview中创建了两个view,然后在view之间添加了约束:
_indicatorConstrainWidth = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view2 attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f];
[_indicatorConstrainWidth setPriority:UILayoutPriorityDefaultLow];
_indicatorConstrainHeight = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view2 attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f];
[_indicatorConstrainHeight setPriority:UILayoutPriorityDefaultLow];
[self addConstraint:_indicatorConstrainWidth];
[self addConstraint:_indicatorConstrainHeight];
现在我想用动画更改乘数属性,但我不知道如何更改乘数属性。 (我在头文件 NSLayoutConstraint.h 的私有属性中找到了 _coefficient,但它是私有的。)
如何更改多重属性?
我的解决方法是删除旧约束并为multipler 添加具有不同值的新约束。
【问题讨论】:
-
您当前删除旧约束并添加新约束的方法是正确的选择。我知道这感觉不“正确”,但这是您应该这样做的方式。
-
我认为乘数不应该是常数。这是一个糟糕的设计。
-
@Borzh 为什么通过乘数我做出自适应约束。对于可调整大小的 ios。
-
是的,我还想更改乘数,以便视图可以保持它与父视图的比例(不是宽度/高度,而是宽度或高度),但奇怪的是苹果不允许这样做。我的意思是这是苹果的糟糕设计,而不是你的。
-
这是一个很棒的演讲,涵盖了这个以及更多youtube.com/watch?v=N5Ert6LTruY
标签: ios iphone objective-c nslayoutconstraint