美文网首页
ios UIButton image 旋转

ios UIButton image 旋转

作者: 王家小雷 | 来源:发表于2019-03-14 20:12 被阅读0次

旋转
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"];

相关文章

网友评论

      本文标题:ios UIButton image 旋转

      本文链接:https://www.haomeiwen.com/subject/kxqhmqtx.html