2011-11-30 61 views
1

鍵我有多個CAKeyframeAnimation對象,每一個類似下面的唯一關鍵:檢索CAKeyframeAnimationKey在AnimationDidStop

..... 
[myAnimation setValues:images]; 
[myAnimation setDuration:1]; 
.... 
[myLayer addAnimation:myAnimation forKey:@"unique key"]; 

我的問題是,如果我有多個動畫像這樣和每一個獨特的關鍵,如何我是否在方法AnimationDidStop中檢索它們的鍵?我希望能夠做到這樣的事情:

-(void)animationDidStop:(CAAnimation*)animation finished:(BOOL)flag{ 
if(..... [email protected]"uniquekey1"){ 
//code to handle this specific animation here: 
}else if(.... [email protected]"uiquekey2"){ 
//code to handle this specific animation here: 
} 
} 

回答

1

Theres沒有公開的API來檢索密鑰。如果你有圖層對象,你可以發送它animationsKeys來獲得它的所有動畫鍵的數組。然後你可以使用animationForKey:來測試每一個。

最簡單的解決方案(除了爲每個動畫使用單獨的委託以外)是創建一個NSMutableDictionary。將動畫對象用作鍵和其動畫鍵字符串作爲其值。