打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

2014.12.30

关注
最开始的想法是让旋转的弧度从0到2 * M_PI,  让动画不停的repeat,实验了一下,没有任何效果,系统动画的时候看到0与2 *M_PI是同一起一始点,所以没有效果。
后来想到一种办法,就是一个变量不断的累加变大,这样影响弧度也随着变化,就达到了圆周运动的效果。
直接上代码:
-(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:^(BOOL finished) {
angle += 10; [self startAnimation];
}];
}
PS:其中angle是double类型。
这下就可以360度旋转了。
还有一种方法:
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat;
[_loadingView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
reference:https://github.com/jonasschnelli/UIView-i7Rotate360
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
如何使用iOS 10的UIViewPropertyAnimator做动画
IOS开发UIView之动画效果的实现方法(合集)
IOS动画总结
ios各种动画效果
iPhone开发中动画
Objective-C中的selector是如何得到参数的?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服