如果在iOS中的NSNotificationCenter声明
一旦结束,我试图开始另一个animation。
我正在检查这样的callback:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(animationDidStopNotification:) name:ImageAnimatorDidStopNotification object:animatorViewController];
我如何做一个if语句,当我收到ImageAnimatorDidStopNotification时,可以触发一些事情?
谢谢!
你没有发布足够的代码来知道你想做什么,问题在哪里。
如果你想链接两个(或更多)animationUIKit,尝试使用setAnimationDidStopSelector:
select器。
- (void)startAnimating { [UIView beginAnimations: @"AnimationOne" context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationOneDidStop:finished:context:)]; /* animation one instructions */ [UIView commitAnimations]; } - (void)animationOneDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context { [UIView beginAnimations: @"AnimationTwo" context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationTwoDidStop:finished:context:)]; /* animation two instructions */ [UIView commitAnimations]; } - (void)animationTwoDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context { [UIView beginAnimations:@"AnimationThree" context:nil]; [UIView setAnimationDuration:1.0]; /* animation three instructions */ [UIView commitAnimations]; }
使用animationDidStop
将animationDidStop
链接在一起对于非常简单的场景非常有用。 但是,对于任何更复杂的事情,它很快变得笨拙。
苹果推荐的更好的方法是利用CAMediaTiming
协议。
他们在第421课“核心animation基础”的WWDC 2011video中给出了一个很好的例子。 你会发现在上面的链接。 您将需要一个开发人员帐户才能访问该帐户。
在video中快速前进到42:36的“通知和时间”提示。