Skip to content

Instantly share code, notes, and snippets.

@faimin
Created May 16, 2017 02:58
Show Gist options
  • Save faimin/1c748f3df647a4f3a305a81cc0012e89 to your computer and use it in GitHub Desktop.
Save faimin/1c748f3df647a4f3a305a81cc0012e89 to your computer and use it in GitHub Desktop.
a UIView category for shaking
- (void)zd_shake:(CGFloat)range {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.duration = 0.5;
animation.values = @[@(-range), @(range), @(-range/2), @(range/2), @(-range/5), @(range/5), @(0)];
animation.repeatCount = CGFLOAT_MAX;
[self.layer addAnimation:animation forKey:@"shake"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment