首页 > 代码库 > iOS 8:CAKeyframeAnimation实现界面晃动动画

iOS 8:CAKeyframeAnimation实现界面晃动动画

QQ空间在输错帐号或密码时会一左一右晃动,这种动画可使用关键帧动画实现。

- (void)shakeView:(UIView *)view {    CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];    shakeAnimation.keyPath = @"transform.translation.x";    CGFloat margin = 10;    shakeAnimation.values = @[@(0), @(-margin), @(margin), @(0)];    shakeAnimation.duration = 0.125;    shakeAnimation.repeatCount = 2;    [view.layer addAnimation:shakeAnimation forKey:nil];}

 

iOS 8:CAKeyframeAnimation实现界面晃动动画