iOS开发动画(Animation)图片360度不停旋转

时间:2022-11-05 20:04:22

 

 

 1 {
 2     CGFloat angle;
 3 }
 4 
 5 - (void)viewDidLoad {
 6     [super viewDidLoad];
 7     angle = 0;
 8     [self startAnimation];
 9 }
10 
11 //方法1
12 -(void) startAnimation
13 {
14     [UIView beginAnimations:nil context:nil];
15     [UIView setAnimationDuration:0.01];
16     [UIView setAnimationDelegate:self];
17     [UIView setAnimationDidStopSelector:@selector(endAnimation)];
18     self.scanImage.transform = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));
19     [UIView commitAnimations];
20 }
21 
22 -(void)endAnimation
23 {
24     angle += 2;
25     [self startAnimation];
26 }
27 
28 //方法2
29 - (void)startAnimation
30 {
31     CGAffineTransform endAngle = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));
32     
33     [UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
34         self.scanImage.transform = endAngle;
35     } completion:^(BOOL finished) {
36         angle += 2; [self startAnimation];
37     }];
38 }