繁体   English   中英

UIView没有动画

[英]UIView doesn't animate

我想为UIView的中心设置动画,我在viewDidLoad中做到了:

_test.center = CGPointMake(100.0,100.0);
[UIView animateWithDuration:10.0 
        delay:5 
        options:UIViewAnimationOptionCurveLinear 
        animations:^{_test.center = CGPointMake(100.0,-100.0);} 
        completion:^(BOOL finished) {

}];

但是当我运行代码时,测试视图的中心已经在100,-100处。 为什么不设置动画?

将代码从viewDidLoad移到viewDidAppear viewDidLoad ,已经加载了UIView ,但尚未在视觉上显示。

我猜您正在使用自动约束,这些约束会阻止您按照自己的方式对视图进行动画处理。

为了解决此问题,请尝试以下步骤:

第一:

将您的代码移动到- (void)viewDidLayoutSubviews

第二:

在对视图执行任何动画之前和之后,请执行以下步骤:

- (void)viewDidLayoutSubviews{

     _test.translatesAutoresizingMaskIntoConstraints = YES;

     _test.center = CGPointMake(100.0,100.0);
     [UIView animateWithDuration:10.0 
                           delay:5 
                         options:UIViewAnimationOptionCurveLinear 
                      animations:^{_test.center = CGPointMake(100.0,-100.0);} 
                      completion:^(BOOL finished) {
                      }];

     [_test updateConstraints];

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM