旋转
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI_4 ];
rotationAnimation.duration = 0.2;
// rotationAnimation.cumulative = YES;
// rotationAnimation.autoreverses=NO;
//防止动画结束回到原始位置
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.repeatCount = 1;//重复次数
[button.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
返回原来位置
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: 0 ];
rotationAnimation.duration = 0.2;
// rotationAnimation.cumulative = YES;
// rotationAnimation.autoreverses=NO;
//防止动画结束回到原始位置
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.repeatCount = 1;//重复次数
//注意一定要是rotationAnimation2不然会很快
[button.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation2"];
网友评论