OC - 25.CAKeyframeAnimation
概述
简介
- CAKeyframeAnimation又称关键帧动画
- CAKeyframeAnimation是抽象类CAPropertyAnimation的子类,可以直接使用
- 通过values与path两个属性指定动画属性
注意事项
- 若指定了path属性,则values属性将被忽略
- CABasicAnimation相当于只有两个关键帧的CAKeyframeAnimation
关键帧动画的常用属性
values(NSArray *)
- 存放关键帧的多个值
- 类似于CABasicAnimation的fromValue与toValue值
path(CGPathRef)
- 动画的执行路径
- 可以通过绘图的方式绘制路径
keyTimes(NSArray *)
- 每个关键帧的执行时间
- 类型为NSNumber类型
- 若不指定,则所有的关键帧平分动画的duration时长
timingFunctions(NSArray *)
- 速度控制函数数组
calculationMode(NSString *)
- 指定关键帧的动画属性
- 若指定该值,则keyTimes与timingFunctions属性值将被忽略
- 默认为:kCAAnimationLinear
rotationMode(NSString *)
- 指定旋转模式,默认为nil
示例
效果图

实现思路
- 通过监听执行动画的UI控件的触摸事件来绘制贝瑟尔曲线
- 创建关键帧动画,指定执行动画的keyPath属性
- 将绘制的贝瑟尔曲线作为动画的执行路径
- 将动画添加到指定的图层上
实现步骤(自定义UIView的子类)
- 使用成员属性保存贝瑟尔路径
@property (nonatomic, strong) UIBezierPath *path;监听触摸事件的状态,绘制贝瑟尔曲线
- 开始
//确定起点
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//获取当前触摸点
UITouch *touch = [touches anyObject];
CGPoint curretnPoint = [touch locationInView:self]; //创建路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:curretnPoint];
//保存路径
self.path = path;
}- 移动
//添加线条
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//获取当前触摸点
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
//添加线条
[self.path addLineToPoint:currentPoint];
//重绘,将曲线显示到图层上
[self setNeedsDisplay];
}- 结束(创建动画)
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//创建动画
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; //指定执行动画的属性,
animation.keyPath = @"position";
//设置动画的执行路径
animation.path = self.path.CGPath; //设置动画的执行时间
animation.duration = 1;
//设置动画的重复次数
animation.repeatCount = MAXFLOAT; //将动画添加到对应的图层上
[[[self.subviews firstObject] layer] addAnimation:animation forKey:nil];
}将路径显示到图层上
//绘制路径
- (void)drawRect:(CGRect)rect
{
[self.path stroke];
}
OC - 25.CAKeyframeAnimation的更多相关文章
- OC基础(25)
NSNumber NSValue NSDate NSFileManager *:first-child { margin-top: 0 !important; } body > *:last-c ...
- OC动画:CAKeyframeAnimation
// 方法一 用法1 Value方式 //创建动画对象 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyP ...
- 25 (OC)* iOS网络HTTP、TCP、UDP、Socket 知识总结
应用层:1.用户接口.应用程序:2.Application典型设备:网关:3.典型协议.标准和应用:TELNET.FTP.HTTP 表示层:1.数据表示.压缩和加密presentation2.典型设备 ...
- c和oc小知识
1.const const 修饰了*p1 / *p2 const int * p1=&age; int const * p2=&age;//和上面的意义一样 ,换句话说就是 在 “ * ...
- oc集合
本人之前学习过一年半ios开发 由于行情太过凄惨,故转前端.心在前端,苹果亦难忘!把我平时的笔记作出给大家总结! 回顾之前的知识 便利初始化函数:框架类库中的一些类有一系列的以init开头的方法,这些 ...
- OC 面试问题汇总
OC 问题汇总: 1. 你如何理解 iOS 内存管理 1. new alloc copy retain这些对象我们都要主动的release或者 autorelease 2. 如果是类方法创建的 ...
- 关于OC中的小数精确计算---NSDecimalNumber
NSDecimalNumber 翻译补充自:http://rypress.com/tutorials/objective-c/data-types/nsdecimalnumber 感谢乐于分享的大神 ...
- Swift - 使用CAKeyframeAnimation实现关键帧动画
1,CAKeyframeAnimation介绍 CAKeyframeAnimation可以实现关键帧动画,这个类可以实现某一属性按照一串的数值进行动画,就像是一帧一帧的制作出来一样. 2,使用样例 ...
- OC的总结 ***希望对大家有帮助*** ---高小杰
1. NSLog 是Foundation提供的一个输出函数,它的功能非常强大,不仅可以输出字符串,还可以输出各种对象,到后面程序还会见到大量的使用NSLog()函数. 2. N ...
随机推荐
- BZOJ1614: [Usaco2007 Jan]Telephone Lines架设电话线
1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 892 Solved: ...
- Welcome Back to C++ (Modern C++)
http://msdn.microsoft.com/en-us/library/hh279654.aspx 看看你是古代还是现代Cpper重点强调 Stack-based scope instead ...
- 【Mongous】write after end
执行1(---) 执行2(----) 完成1(POST) 执行3(---)
- 网络流(最大流)CodeForces 512C:Fox And Dinner
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...
- VS2010 快速写入注释小技巧
/************************************************************************//* *//******************* ...
- 【转】Gabor 入门
Computer Vision Tutorials Search Primary Menu Skip to content Tutorials Search for: Gabor Filters ...
- JSP路径的问题
JSP因为是客户端使用的路径,所以完全可以使用全路径形式 那么在JSP里面使用路径的方式有两种,超链接或者form 当我们在MyEclipse中新建JSP时,可以发现有下面 <%@ page l ...
- IOS开发中 RunLoop,RunTime
1.Objective-C中的函数调用 对于C语言,函数调用是由编译器直接转化完成的,在编译时程序就开始查找要执行的函数(C语言函数调用原理).而在OC中,我们将函数调用称为消息发送.在编译时程序不查 ...
- PHP+IIS7+PHPMangerForIIS搭建开发环境
准备工作 1.安装IIS 2.安装php 3.安装phpmanager 准备工作做好后,开始搭建环境 1.在Internet信息服务管理器下找到PHPManager 2.点击Register new ...
- 触发器记录表某一个字段数据变化的日志 包括插入insert 修改update 删除delete 操作
本文参考:http://www.cnblogs.com/lyhabc/articles/3236985.html ,), ), ), ), ...