CABaseAnimation动画收录:一、 iOS做旋转动画的几种方法
来源:互联网 发布:js获取标签名称 编辑:程序博客网 时间:2024/06/03 23:39
iOS中可能会用到一些旋转动画的效果,这部分动画其实主要使用的还是CoreAnimation进行,实现起来有好几种方法,但最终的效果都是一样的
上代码
第一种:使用CABasicAnimated方法
这种方法是最简单的方法
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@“transform.rotation.z"];
//默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
animation.fromValue = [NSNumbernumberWithFloat:0.f];
animation.toValue = [NSNumbernumberWithFloat: M_PI *2];
animation.duration = 3;
animation.autoreverses = NO;
animation.fillMode =kCAFillModeForwards;
animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
[view.layer addAnimation:animation forKey:nil];
这种方法用到了CoreGraphics库中的CGPathAddArc方法
CGMutablePathRef path = CGPathCreateMutable();
//CGPathAddArc函数是通过圆心和半径定义一个圆,然后通过两个弧度确定一个弧线。注意弧度是以当前坐标环境的X轴开始的。
//需要注意的是由于iOS中的坐标体系是和Quartz坐标体系中Y轴相反的,所以iOS UIView在做Quartz绘图时,Y轴已经做了Scale为-1的转换,因此造成CGPathAddArc函数最后一个是否是顺时针的参数结果正好是相反的,也就是说如果设置最后的参数为1,根据参数定义应该是顺时针的,但实际绘图结果会是逆时针的!
//严格的说,这个方法只是确定一个中心点后,以某个长度作为半径,以确定的角度和顺逆时针而进行旋转,半径最低设置为1,设置为0则动画不会执行
CGPathAddArc(path, NULL, view.centerX, view.centerY, 1, 0,M_PI * 2, 1);
CAKeyframeAnimation * animation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
animation.path = path;
CGPathRelease(path);
animation.duration = 3;
animation.repeatCount = 500;
animation.autoreverses = NO;
animation.rotationMode =kCAAnimationRotateAuto;
animation.fillMode =kCAFillModeForwards;
[layer addAnimation:animation forKey:nil];
[view.layer addAnimation:animation2 forKey:nil];
- CABaseAnimation动画收录:一、 iOS做旋转动画的几种方法
- iOS做旋转动画的几种方法
- iOS动画 CABaseAnimation总结
- CABaseAnimation收录:二、CAAnimation动画详解
- iOS核心动画-CABaseAnimation
- iOS 旋转动画的几种实现方式
- 利用MCGS做旋转动画的方法
- 用css3制作旋转加载动画的几种方法
- 用css3制作旋转加载动画的几种方法
- CABaseAnimation + CAAnimationGroup + CAKeyframeAnimation的简单动画
- iOS开发-autolayout动画效果实现的几种方法
- ios 实现动画的几种方式
- IOS几种实现动画的方式
- 加载JIF动画的几种方法
- 27.iOS 动画 旋转
- iOS旋转动画
- iOS 旋转动画
- ios动画旋转方向
- jmeter 所遇到问题 集合
- 卷积的理解
- rbtree
- nginx与ftp服务器出现403错误
- sensor和layout设计规范
- CABaseAnimation动画收录:一、 iOS做旋转动画的几种方法
- 奇怪的键盘--2015蓝桥杯
- sql 2017-10-27
- Android 超简单音乐播放器(十二)换个歌词和删除歌曲
- 时间序列分析(一)
- EasyUI一些布局(基本介绍)以及运行结果
- markdown语法
- equals&hashCode
- ngFileUpload注不进去