views:

41

answers:

1

I'm using core animation to transition between different view states in my application. However, I need to find a way to perform different tasks after the animations finish. I understand I can implement a delegate method and use the

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

callback, however there's no easy way of keeping track of which animation is ending.

I can think of some tedious solutions, like using a series of flags and counters, however I'm wondering if there is a more efficient and practical method to getting around this problem.

What are some thoughts?

+1  A: 

Use setValue:ForKey method to assign a unique name to each animation.

[animation setValue:@"myUniqueName" forKey:@"name"];

Later, in the animationDidStop method use that to find out which animation stopped

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished {
    if([[theAnimation valueForKey:@"name"] isEqual: @"myUniqueName"] && finished){
               //code
    } 
    if([[theAnimation valueForKey:@"name"] isEqual: @"otherName"] && finished){
        //code
    } 
}
Mihir Mathuria
Perfect thanks!
Scott Langendyk