iOS开发动画(Animation)图片360度不停旋转
后来想到一种办法,就是一个变量不断的累加变大,这样影响弧度也随着变化,就达到了圆周运动的效果。
直接上代码:
当然你可以用block的方式写也是一样的。
PS:其中angle是double类型。
这下就可以360度旋转了。
还有一种方法:
reference:https://github.com/jonasschnelli/UIView-i7Rotate360
/
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 }