我有这个简单的观点:
- (void)viewDidLoad { [super viewDidLoad]; redBox = [[UIView alloc] init]; [redBox setBackgroundColor:[UIColor redColor]]; [redBox setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.view addSubview:redBox]; //H: widthConstraint = [NSLayoutConstraint constraintWithItem:redBox attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0.0]; [self.view addConstraint:widthConstraint]; //More constraints... }
我想动画一下redBox宽度的增加.
我试过这个:
widthConstraint.constant = 100; [UIView animateWithDuration:1 animations:^{ [self.view layoutIfNeeded]; } ];
这会将视图的宽度增加100并对其进行动画处理,但我需要将其增加一个与其超视图宽度成比例的量.换句话说,我想设置widthConstraint
S" multiplier
来0.8
.
但是NSLayoutConstraint
的multiplier
是只读的!这是否意味着我widthConstraint
每次想要对其进行动画修改时都必须删除,修改和重新添加,multiplier
还是有更好的方法?