0
点赞
收藏
分享

微信扫一扫

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

路西法阁下 2022-03-30 阅读 68


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、效果

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




作者:​​ CH520​​


举报

相关推荐

0 条评论