如何在iOS中永久重复播放动画? [英] How to repeat animation forever in iOS?

查看:1143
本文介绍了如何在iOS中永久重复播放动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想永远重复播放动画。下面是我的代码:

I want to repeat an animation forever in my view. Below is my code:

[UIView animateWithDuration:0.5f
        delay:0.49f
        options:UIViewAnimationOptionCurveEaseInOut
        animations:^{
        //for IMMERSE
        [_pic2 setAlpha:1.0f];
         _view1_immerse=_pic2.frame;
         _view1_immerse.origin.x = ([UIScreen mainScreen].bounds.size.width-_view1_immerse.size.width)/2;
         self.pic2.frame=_view1_immerse;
         }
         completion:^(BOOL finished){
         [UIView animateWithDuration:0.5f delay:0.49f options:UIViewAnimationOptionCurveEaseOut animations:^{
         _view1_immerse=_pic2.frame;
         _view1_immerse.origin.x = [UIScreen mainScreen].bounds.size.width;
         self.pic2.frame=_view1_immerse;
         [_pic2 setAlpha:0.0];
         } completion:^(BOOL finished){
         [UIView animateWithDuration:0.0f animations:^{
         _view1_immerse=_pic2.frame;
         _view1_immerse.origin.x = -_view1_immerse.size.width;
         self.pic2.frame=_view1_immerse;
                                     }];
                                 }];
                             }];

我尝试添加选项 UIViewAnimationOptionRepeat ,但是似乎它只重复最外层的动画部分。我想重复整个动画。

I tried adding option UIViewAnimationOptionRepeat, but it seems that it only repeats the "animation" part of the most outside layer. I want to repeat the whole set of animation.

而且我不想使用 NSTimer
有人可以给我一些有关我的问题的建议吗?

And I do not want to use NSTimer. Could anyone give me some advice about my problem?? Thanks in advance!

推荐答案

您可以在下面的代码中查看重复动画。

You can check below code for repeat animation.

[UIView animateWithDuration:1.0f
                  delay:0.0f
                options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState
             animations: ^(void){self.view.center = CGPointMake(0, 200);}
             completion:NULL];

谢谢


Swift 4

UIView.animate(withDuration: 100,
                   delay: 0,
                   options: [.repeat, .autoreverse, .beginFromCurrentState],
                   animations: {

    }, completion: nil)

这篇关于如何在iOS中永久重复播放动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆