1、目的
- 为了按钮上的图片有一个360度动画旋转效果。
 
2、代码
- (void)changeAction:(UIButton *)changeBtn {
    
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 0.6;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 2;
    [changeBtn.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}3、调用
UIButton *refreshButton = [[UIButton alloc] init];
[self.view addSubview:refreshButton];
[refreshButton setImage:[UIImage imageNamed:@"icon_refresh"] forState:UIControlStateNormal];
[refreshButton makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(self.view).offset(-30);
    make.bottom.equalTo(settingButton);
    make.width.height.equalTo(60);
}];
[refreshButton addTarget:self action:@selector(changeAction:) forControlEvents:UIControlEventTouchUpInside];4、效果

作者: CH520










