如何在iOS中永远重复动画?

如何在iOS中永远重复动画?,ios,objective-c,animation,Ios,Objective C,Animation,我想在我的视图中永远重复动画。下面是我的代码: [UIView animateWithDuration:0.5f delay:0.49f options:UIViewAnimationOptionCurveEaseInOut animations:^{ //for IMMERSE [_pic2 setAlpha:1.0f]; _view1_immerse=_pic2.frame;

我想在我的视图中永远重复动画。下面是我的代码:

[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;
                                     }];
                                 }];
                             }];
我尝试添加选项
uiviewmanimationoptionrepeat
,但它似乎只重复最外层的“动画”部分。我想重复整套动画

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

谁能就我的问题给我一些建议??提前谢谢

您可以检查下面的代码以获得重复动画

[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)

ui视图动画选项repeat
放在内部动画而不是上部动画上。如果这不起作用,请使用关键帧动画。有没有办法在一段时间后停止它?
[view.layer removeAllAnimations]