2009-10-15 51 views
0

我有一個隱式的動畫如下:是否可以在iPhone上爲動畫設置標籤或ID?

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationDelegate:self]; 

... 

[UIView commitAnimations]; 

當這個動畫的起點和終點,它會觸發這些委託功能:

- (void)animationWillStart:(NSString *)animationID context:(void *)context; 

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag; 

我有得到我的viewController動畫多的東西,和代表功能越來越多。如何標記特定的動畫,以便我可以檢查它在委託功能中的哪一個?

我也很奇怪,其中一個函數的參數是一個字符串,而另一個是CAAnimation。這兩種方法都會被調用,但是我使用了錯誤的還是什麼?

回答

3

對於這樣的隱式動畫,您將animationDidStopSelector

[UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)]; 

,這將打電話給你animationDidEnd如下:

- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 

這幾乎是一樣的,其調用beginAnimations:context:animationWillStartSelecter

對於兩者,您都可以使用上下文來傳遞標籤或其他值選擇器可以用來區分動畫。

1
[UIView beginAnimations:nil context:nil]; 

我在這裏瘋了還是有一些原因,你傳遞在零的animationID(第一個參數)?無需混淆上下文,只需設置ID,然後查看傳入您的didStop選擇器的ID即可。這就是它的原因!

+0

啊,謝謝。我想我沒有意識到第一個理由是什麼。我確實通過將animationDidEnd選擇器設置爲一個獨特的函數來獲得此工作,但知道如何正確設置ID並使用委託方法是很好的。 +1 –

相關問題