Created
November 8, 2011 15:37
-
-
Save Sai/1348075 to your computer and use it in GitHub Desktop.
Shaky Layer
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
#define degreesToRadian(x) (M_PI * (x) / 180.0) | |
+ (void)shakyWithLayer:(CALayer *)layer delegate:(id)object forKey:(NSString *)key { | |
CAKeyframeAnimation * animation; | |
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"]; | |
animation.duration = 0.25; | |
animation.cumulative = YES; | |
animation.repeatCount = 9999; | |
animation.values = [NSArray arrayWithObjects: | |
[NSNumber numberWithFloat: 0.0], | |
[NSNumber numberWithFloat: degreesToRadian(-4.0)], | |
[NSNumber numberWithFloat: 0.0], | |
[NSNumber numberWithFloat: degreesToRadian(4.0)], | |
[NSNumber numberWithFloat: 0.0], nil]; | |
animation.fillMode = kCAFillModeForwards; | |
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; | |
animation.removedOnCompletion = NO; | |
animation.delegate = object; | |
[layer addAnimation:animation forKey:key]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment