效果图
核心代码
/*** CAKeyframeAnimation ***/
//transform.translation.x
- (CAKeyframeAnimation *)keyframeAnimation
{
CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
animation.delegate = self;
animation.duration = 1;
animation.values = @[ @(0), @(10), @(-8), @(8), @(-5), @(5), @(0) ];
animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
return animation;
}
使用:[anyView.layer addAnimation:[self keyframeAnimation] forKey:@"shake"];