Created
May 16, 2017 02:58
-
-
Save faimin/1c748f3df647a4f3a305a81cc0012e89 to your computer and use it in GitHub Desktop.
a UIView category for shaking
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
- (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