2012-01-14 73 views
6

我試圖找到一種方法來檢測視圖是否正在動畫。有沒有辦法在iOS中檢測正在運行的動畫?

案例:我已視圖的層上施加了陰影,指定爲性能shadowPath。當視圖被調整大小時,陰影應該隨着動畫。我可以觀察視圖的框架,並相應地更改圖層的shadowPath。但是當視圖正在調整大小時,由於變化沒有動畫,因此影子會跳躍前進。

我知道如何使用CABasicAnimation動畫shadowPath,但我需要知道正在進行的動畫的屬性,以便我可以將它們應用於我的動畫(主要是:duration,easing)。

這是一個框架型元件,所以我不能假設我知道事先的持續時間和寬鬆的屬性。

有沒有一種方法來檢測啓動/觀察幀時,正在運行的動畫?

回答

12

你可以通過調用

[yourView.layer animationForKey:@"key"] 

讓所有的鍵檢索連接到特定視圖的層中的所有動畫知道它的關鍵有一些動畫,來電

NSArray* keys = [yourView.layer animationKeys]; 
+0

啊很大。謝謝! – Inferis 2012-01-17 10:38:06

0

我認爲最好的做法應該是....

UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.7]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 

.....your code 
// Set animation did stop selector before committing the animations 

[UIView setAnimationDidStopSelector:@selector(animationFinished:)]; 

[UIView commitAnimations]; 
相關問題