美文网首页
iOS 360旋转动画效果

iOS 360旋转动画效果

作者: zxb有缘 | 来源:发表于2021-06-08 09:03 被阅读0次

AnimationsView_1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, imageView.width , imageView.width *(150.0/1788.0))];
AnimationsView_1.image=imageNamed(@"PointerIocon");
AnimationsView_1.centerX=self.width/2.0;
AnimationsView_1.centerY=imageView.centerY;
[self addSubview:AnimationsView_1];

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = 5;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1000;
  
[AnimationsView_1.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

其他方法:

-(void) startAnimation

{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.01];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(endAnimation)];

imageView.transform = CGAffineTransformMakeRotation(angle * (M_PI / 180.0f));

[UIView commitAnimations];

}

-(void)endAnimation

{

angle += 10;

[self startAnimation];

}

当然你可以用block的方式写也是一样的。

  • (void)startAnimation

{

CGAffineTransform endAngle = CGAffineTransformMakeRotation(imageviewAngle * (M_PI / 180.0f));

[UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{

imageView.transform = endAngle;

} completion:^(BOOLfinished) {

angle += 10; [self startAnimation];

}];

}

PS:其中angle是double类型。

这下就可以360度旋转了。

相关文章

网友评论

      本文标题:iOS 360旋转动画效果

      本文链接:https://www.haomeiwen.com/subject/lwzzsltx.html