如何检查UIImageView是否已完成其动画

如何检查UIImageView是否已完成其动画

问题描述:

我是iPhone开发新手。我正在使用UIImageView来为数组中的图像设置动画。我决定通过名为isAnimating的房产停止动画。但它总是返回真实。如何检查UIImageView是否已完成其动画

我想检查一下动画是否完成,或者有一段时间还没完成动画。

请让我知道,我该如何检查它。

+0

你可以显示你的动画代码,所以我们可以帮助更好? – 2012-02-03 15:59:20

你应该做的动画块内部动画:

[UIView animateWithDuration:duration animations:^{ 
    //animation code here 
} completion:^(BOOL finished) 
{ 
    //this will be called when the animation is finished 
}]; 

编辑:这个答案是错误的,也许不应该被接受,任何人来到这里寻找正确的答案:this回答这个问题,我认为

+1

我知道,animateWithDuration:completion:用来做iOS动画(比如alpha淡入淡出,运动,缩放,旋转等等)。我发现他接受了这个答案,但我相信最初的问题必须与通过设置'animationImages'属性来检测'UIImageView'的结束动画UIImage数组。我很想看到有关如何检测该动画集结束的答案。 – Olie 2012-11-01 22:13:41

使属性BOOL IsAnimating 然后执行该代码

{ 
    [UIView beginAnimations:@"Animation of ImageVIew Begins" context:nil]; 
      IsAnimating =YES; 

    [UIView setAnimationDuration:0.4]; //you can put your time 
    NSLog(@" Animating"); 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(AnimationComplete)]; 

// Your animation code here  
    [UIView commitAnimations]; 
} 


- (void) AnimationComplete 
{ 
    isAnimating = NO; 
} 

你BOO l变量将为YES,直到动画完成为止。然后它将变为否

+0

我会为此投票 - 如果不坚持[命名约定](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB)不会那么烦人 – vikingosegundo 2012-02-03 20:28:23

根据持续时间使用委托来触发接收器上所需的任何方法。