ios – 自动布局:动画更改为NSLayoutConstraint的乘数

我有这个简单的观点:
- (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的乘数设置为0.8.

但是NSLayoutConstraint’s multiplier is readonly!这是否意味着每次我想要对其乘数进行动画处理时,我必须删除,修改和重新添加widthConstraint,还是有更好的方法

解决方法

不幸的是,没有更好的方法.使用不同的乘数删除和重新添加是您唯一的选择.请提交一个您希望看到多重读取的错误.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...