@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"];
}