Skip to content

Instantly share code, notes, and snippets.

@psobko
Created November 6, 2013 20:11
Show Gist options
  • Save psobko/7343267 to your computer and use it in GitHub Desktop.
Save psobko/7343267 to your computer and use it in GitHub Desktop.
//I created a typedef for a block:
typedef void (^animationCompletionBlock)(void);
// And a key that I use to add a block to an animation:
#define kAnimationCompletionBlock @"animationCompletionBlock"
// Then, if I want to run animation completion code after a CAAnimation finishes, I set myself as the delegate of the animation, and add a block of code to the animation using setValue:forKey:
animationCompletionBlock theBlock = ^void(void)
{
//Code to execute after the animation completes goes here
};
[theAnimation setValue: theBlock forKey: kAnimationCompletionBlock];
// Then, I implement an animationDidStop:finished: method, that checks for a block at the specified key and executes it if found:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
animationCompletionBlock theBlock = [theAnimation valueForKey: kAnimationCompletionBlock];
if (theBlock)
theBlock();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment