版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013127850/article/details/78919115
@property (nonatomic , strong) UIView *demoView;
/**
* 抖动效果
*/
-(void)shakeAnimation{
CAKeyframeAnimation *anima = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];//在这里@"transform.rotation"==@"transform.rotation.z"
NSValue *value1 = [NSNumber numberWithFloat:-M_PI/180*4];
NSValue *value2 = [NSNumber numberWithFloat:M_PI/180*4];
NSValue *value3 = [NSNumber numberWithFloat:-M_PI/180*4];
// 如果把动画的duration设置为3秒,而speed设置为2,动画将会在1.5秒结束,因为它以两倍速在执行。
// anima.duration = 2.0f;
// anima.repeatCount = MAXFLOAT;
anima.values = @[value1,value2,value3];
//速度
anima.speed = 1;
//重复次数
anima.repeatCount = 3;
[_demoView.layer addAnimation:anima forKey:@"shakeAnimation"];
}