Created
May 13, 2014 12:12
-
-
Save izackp/eb5c6a6cf9f52d6d1f99 to your computer and use it in GitHub Desktop.
A simple rubber band pop animation I created.
This file contains 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
#import <UIKit/UIKit.h> | |
@interface UIView (Pop) | |
- (void)popWithMagnitude:(CGFloat)magnitude numPops:(int)numPops duration:(CGFloat)duration; | |
@end |
This file contains 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
#import "UIView+Pop.h" | |
@implementation UIView (Pop) | |
- (void)popWithMagnitude:(CGFloat)magnitude numPops:(int)numPops duration:(CGFloat)duration { | |
numPops -=1; | |
void (^growAnimation)() = ^{ | |
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f + magnitude, 1.0f + magnitude); | |
}; | |
void (^shrinkAnimation)() = ^{ | |
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f - magnitude * 0.75f, 1.0f - magnitude * 0.75f); | |
}; | |
void (^shrinkCompletion)(BOOL) = ^(BOOL finished) { | |
if (numPops == 0) | |
{ | |
[UIView animateWithDuration:duration * 1.5f animations:^{ | |
self.transform = CGAffineTransformIdentity; | |
} completion:nil]; | |
return; | |
} | |
[self popWithMagnitude:magnitude * 0.5f numPops:numPops duration:duration * 1.5f]; | |
}; | |
void (^growCompletion)(BOOL) = ^(BOOL finished) { | |
[UIView animateWithDuration:duration * 1.25f animations:shrinkAnimation completion:shrinkCompletion]; | |
}; | |
[UIView animateWithDuration:duration animations:growAnimation completion:growCompletion]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment