Scott Langendyk
Scott Langendyk

Reputation: 301

Core Animation Callbacks

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?

Upvotes: 2

Views: 1299

Answers (1)

Mihir Mathuria
Mihir Mathuria

Reputation: 6539

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
    } 
}

Upvotes: 7

Related Questions