微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,还是有更好的方法

解决方法

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

原文地址:https://www.jb51.cc/iOS/333435.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐