iOS开发中让UIButton上的image进行360度旋转

背景:

在项目中的一个网页中有一个“换一换”按钮,点击更换页面上的书籍。在原生页面也有一个“换一换”按钮,该按钮样式和功能都和网页中的“换一换”按钮一样。两者不同的是点击网页中的“换一换”按钮,按钮上的图片会有一个360度旋转的动画效果,而原生的没有任何效果。为了统一,要求在点击原生的“换一换”按钮时,上面的图片也有一个360度动画旋转效果。

代码:

- (void)changeAction:(UIButton *)changeBtn{

    CABasicAnimation* rotationAnimation;

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 ];

    rotationAnimation.duration = 0.4;

    rotationAnimation.cumulative = YES;

    rotationAnimation.repeatCount = 2;

    [changeBtn.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

}

效果图:

这里写图片描述

旋转
本篇文章到这里就结束了,愿大家加班不多工资多,男同胞都有女朋友,女同胞都有男朋友。

猜你喜欢

转载自blog.csdn.net/u010105969/article/details/79877908