2012-02-03 79 views
2

我是iPhone開發新手。我正在使用UIImageView來爲數組中的圖像設置動畫。我決定通過名爲isAnimating的房產停止動畫。但它總是返回真實。如何檢查UIImageView是否已完成其動畫

我想檢查一下動畫是否完成,或者有一段時間還沒完成動畫。

請讓我知道,我該如何檢查它。

+0

你可以顯示你的動畫代碼,所以我們可以幫助更好? – 2012-02-03 15:59:20

回答

-4

你應該做的動畫塊內部動畫:

[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

1

使屬性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

0

根據持續時間使用委託來觸發接收器上所需的任何方法。

相關問題