开发者社区> 贱见> 正文

IOS 核心动画之CAKeyframeAnimation - iBaby

简介: <p style="padding-top:0px; padding-bottom:0px; margin-top:8px; margin-bottom:8px; line-height:22.5px; letter-spacing:0.5px; font-size:13px; word-wrap:break-word; word-break:break-all; color:rgb(51
+关注继续查看

- IOS 核心动画之CAKeyframeAnimation 

- 简单介绍 

是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSArray保存这些数值 

- 属性解析: 

- values:就是上述的NSArray对象。里面的元素称为”关键帧”(keyframe)。动画对象会在指定的时间(duration)内,依次显示values数组中的每一个关键帧 

- path:可以设置一个CGPathRef\CGMutablePathRef,让层跟着路径移动。path只对CALayer的anchorPoint和position起作用。如果你设置了path,那么values将被忽略 

- keyTimes:可以为对应的关键帧指定对应的时间点,其取值范围为0到1.0,keyTimes中的每一个时间值都对应values中的每一帧.当keyTimes没有设置的时候,各个关键帧的时间是平分的 

- 说明:CABasicAnimation可看做是最多只有2个关键帧的CAKeyframeAnimation 

- Values方式: 

- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; 

animation.keyPath = @"position"; 

NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; 

NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)]; 

NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(200, 200)]; 

NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(100, 200)]; 

NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; 

animation.values=@[value1,value2,value3,value4,value5]; animation.repeatCount=MAXFLOAT; 

animation.removedOnCompletion = NO; 

animation.fillMode = kCAFillModeForwards; 

animation.duration = 4.0f; 

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 

animation.delegate=self; 

[self.myView.layer addAnimation:animation forKey:nil]; 

- Path方式: 

- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; 

animation.keyPath = @"position"; 

CGMutablePathRef path=CGPathCreateMutable(); 

CGPathAddEllipseInRect(path, NULL, CGRectMake(150, 100, 100, 100)); 

animation.path=path; 

CGPathRelease(path); 

animation.repeatCount=MAXFLOAT; 

animation.removedOnCompletion = NO; 

animation.fillMode = kCAFillModeForwards; 

animation.duration = 4.0f; 

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 

animation.delegate=self; 

[self.myView.layer addAnimation:animation forKey:nil]; 

- keyPath可以使用的key 

- #define angle2Radian(angle) ((angle)/180.0*M_PI) 

- transform.rotation.x 围绕x轴翻转 参数:角度 angle2Radian(4) 

transform.rotation.y 围绕y轴翻转 参数:同上 

transform.rotation.z 围绕z轴翻转 参数:同上 

transform.rotation 默认围绕z轴 

transform.scale.x x方向缩放 参数:缩放比例 1.5 

transform.scale.y y方向缩放 参数:同上 

transform.scale.z z方向缩放 参数:同上 

transform.scale 所有方向缩放 参数:同上 

transform.translation.x x方向移动 参数:x轴上的坐标 100 

transform.translation.y x方向移动 参数:y轴上的坐标 

transform.translation.z x方向移动 参数:z轴上的坐标 

transform.translation 移动 参数:移动到的点 (100,100) 

opacity 透明度 参数:透明度 0.5 

backgroundColor 背景颜色 参数:颜色 (id)[[UIColor redColor] CGColor] 

cornerRadius 圆角 参数:圆角半径 5 

borderWidth 边框宽度 参数:边框宽度 5 

bounds 大小 参数:CGRect 

contents 内容 参数:CGImage 

contentsRect 可视内容 参数:CGRect 值是0~1之间的小数 

hidden 是否隐藏 

position 

shadowColor 

shadowOffset 

shadowOpacity 

shadowRadius 


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程
iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程
88 0
iOS动画开发之四——核心动画编程(CoreAnimation)
iOS动画开发之四——核心动画编程(CoreAnimation)
81 0
iOS - Core Animation 核心动画
1、UIView 动画 具体讲解见 iOS - UIView 动画 2、UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3、CADisplayLink 定时器 具体讲解见 iOS - OC NSTimer 定时器 CADisplayLink 是一个能让我们以和屏幕刷新率相同的频率将内容画到屏幕上的定时器。
1205 0
iOS - Core Animation 核心动画的使用
1、简单使用示例 1.1 时钟 QClockView.h @interface QClockView : UIView /// 创建时钟界面 + (instancetype)q_clockViewWithFrame:(CGRect)frame; @end QClockView.
1153 0
+关注
贱见
文章
问答
视频
相关电子书
更多
深入剖析iOS性能优化
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载