Search code examples
iosanimationuikitcore-animation

If statement on NSNotificationCenter in iOS


I'm trying start another animation when one ends.

I am checking for callbacks like this:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(animationDidStopNotification:) 
name:ImageAnimatorDidStopNotification 
object:animatorViewController];

How do I make an if statement that lets me do trigger something when ImageAnimatorDidStopNotification is received?

Thanks!


Solution

  • You didn't post enough code to know what are you trying to do and where is the problem.

    If you want to chain two (or more) animations with UIKit, try using setAnimationDidStopSelector: selector.

    - (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];
    }