我有这个简单的观点:
- (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... }
我试过这个:
widthConstraint.constant = 100; [UIView animateWithDuration:1 animations:^{ [self.view layoutIfNeeded]; } ];
这会将视图的宽度增加100并对其进行动画处理,但我需要将其增加一个与其超视图宽度成比例的量.换句话说,我想将widthConstraint的乘数设置为0.8.
但是@L_301_0@!这是否意味着每次我想要对其乘数进行动画处理时,我必须删除,修改和重新添加widthConstraint,还是有更好的方法?