如何突然结束动画?

时间:2012-09-10 12:20:08

标签: ios xcode

我正在制作一个游戏,当用户进行移动时,源和目标方块在动画中亮起。动画持续时间为1秒。

问题是当用户过快地点击前进按钮时,所有源和目标方块都会亮起,导致由于第二个动画在第一个动画结束之前开始而出现许多亮起方块。

如果动画的持续时间没有结束,我怎么能突然结束动画。

动画功能代码: -

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:value];
    [UIView setAnimationRepeatCount:1];
   // [UIView setAnimationRepeatAutoreverses:YES];

    [self.view viewWithTag:(src+1)+2000].backgroundColor=[UIColor orangeColor];
    [self.view viewWithTag:(src+1)+2000].backgroundColor=[UIColor clearColor];
    [self.view viewWithTag:(dest+1)+2000].backgroundColor=[UIColor orangeColor]; 
    [self.view viewWithTag:(dest+1)+2000].backgroundColor=[UIColor clearColor];
    [UIView commitAnimations];

注意: - 我接受投票作为一种健康的批评方式,但确实写下了原因,以便我可以提高

1 个答案:

答案 0 :(得分:1)

使用

#import <QuartzCore/QuartzCore.h>

.......

[myView.layer removeAllAnimations];
希望它有所帮助。快乐的编码:)

相关问题