【问题标题】:animations on infinite loop无限循环动画
【发布时间】:2010-10-11 19:41:35
【问题描述】:

我有 5 种不同的动画,它们会一个接一个地动画然后消失。有没有办法将它们置于无限循环中,以便动画 #1 开始和结束,然后动画 #2 开始和结束等等。然后整个过程将在无限循环中重复。

我在延迟时将动画放在单独的块中。我猜有更好的方法来做到这一点。这是我目前拥有的:

-(void) firstAnimation {

        [UIView beginAnimations:@"Fade Out Image" context:nil];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDelay:40];
        [UIView setAnimationRepeatCount:30];
        [UIView setAnimationRepeatAutoreverses:YES]; 
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        theImage.alpha = 1;
        theImage.alpha = 0.1;

        [UIView commitAnimations];

        [self secondAnimation];

}

-(void) secondAnimation {

        tapImage2.hidden = NO;

        [UIView beginAnimations:@"Fade Out Image" context:nil];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDelay:53];
        [UIView setAnimationRepeatCount:29];
        [UIView setAnimationRepeatAutoreverses:YES];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        theImage2.alpha = 1;
        theImage2.alpha = 0.1;      

        [UIView commitAnimations];

    [self thirdAnimation];

}

这会持续 5 个动画。感谢您的帮助。

【问题讨论】:

    标签: iphone objective-c core-animation infinite-loop


    【解决方案1】:

    不使用延迟,而是设置动画委托并创建动画完成方法。我注意到您已经在设置委托了。

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    
    - (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
        //Start next animation based on the animationID of the last one...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-08
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 2022-08-16
      相关资源
      最近更新 更多