Created
November 6, 2013 20:11
-
-
Save psobko/7343267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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