Skip to content

Instantly share code, notes, and snippets.

@Sai
Created November 8, 2011 15:37
Show Gist options
  • Save Sai/1348075 to your computer and use it in GitHub Desktop.
Save Sai/1348075 to your computer and use it in GitHub Desktop.
Shaky Layer
#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