不停旋转的图片
来源:互联网 发布:淘宝流量 爱逛街 编辑:程序博客网 时间:2024/04/27 21:41
问题描述
最近要做一个图片360°不停旋转的功能,最初想到的便是是用UIView封装的动画来做。但是设置了0到2π的动画,让它不停的旋转,但是问题出现了,设置了之后它为什么不会动呢?原来UIView的动画是从起始位置和结束为止进行计算,然后进行补间,但是0和2πUIView封装动画认为它是一个位置,所以就没有任何补间出现!
解决方案
网上搜索了一下,大致有两种思路,一种是先让它旋转一定的角度,然后重复调用,一直旋转下去,另外一种是CoreAnimation来实现,总体上还是比较简单的
1.旋转一定的角度,重复调用
1.1
-(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]; }
1.2
- (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]; }]; }
2.CoreAnimation实现方法
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"];
0 0
- 不停旋转的图片
- CSS图片不停旋转
- CSS 图片不停旋转
- Android 不停旋转图片
- 不停旋转的舞步
- android 动画rotate实现图片不停旋转的效果
- 如何实现图片的3D旋转,而且是不停旋转?
- 不停闪烁的图片
- Android中如何使用rotate实现图片不停旋转的效果与动画的停止
- 让一个按钮一直不停的旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- Android Tween动画之RotateAnimation实现图片不停旋转
- iOS开发动画(Animation)图片360度不停旋转
- 浅谈Python装饰器
- Linux_ select demo
- 移动构造-C++11
- 课程练习一-Problem Q
- 宗海图绘制的关键问题
- 不停旋转的图片
- Linux _ share 内存共享
- 服务器数据抓包排查数据收发是否正常
- C++:移动构造和移动赋值
- EasyUi的tab组件href属性链接的页面JS代码无法执行
- java集合的讲解
- CDOJ 1131 男神的礼物 石子合并
- lightoj 1166 1166 - Old Sorting 贪心
- 81192!请返航!