ios系统框架一: Core Animation
核心动画是一套包含图形绘制,投影,动画的Objective–C类集合。它通过开发人员所熟悉的应用程序套件和Cocoa Touch视图架构的抽象分层模式,同时使用先进的合作效果提供了一套流畅的动画。
使用核心动画,你只需要设置一些参数比如起点和终点,剩下的帧核心动画为你自动完成。
核心动画类有以下分类:
- 提供显示内容的图层类。
- 动画和计时类。
- 布局和约束类。
- 事务类,在原子更新的时候组合图层类。
核心动画的基础类包含在Quartz核心框架(Quartz Core framework)里面。
图层类是核心动画的核心基础,它提供了一套抽象的概念(假如你使用过NSView或者UIView的话,你一定会对它很熟悉)。CALayer是整个图层类的基础,它是所有核心动画图层类的父类。
虽然核心动画的图层和 Cocoa的视图在很大程度上没有一定的相似性,但是他们两者最大的区别是,图层不会直接渲染到屏幕上。
在模型-视图-控制器(model-view-controller)概念里面NSView和UIView是典型的视图部分,但是在核心动画里面图层是模型部分。图层封装了几何、时间、可视化属性,同时它提供了图层现实的内容,但是实际显示的过程则不是由它来完成。
图层树是核心动画里面类似Cocoa视图的层次结构。比如一个NSView或者UIView的实例拥有父视图(superview)和子视图(subview),一个核心动画的图层拥有父图层(suplayer)和子图层(sublayer)
动画类:
一个基础动画仅仅需要要你指定一个开始的值和一个结束的值,或者目前的值,关键帧动画可以使你指定:
每个关键帧的一个数组值,例如,你可以给一个CGColorRef对象的一个数组,用来改变背景的颜色。
在0.0和1.0之间的一个数组值,用来给每个帧指定总时间中所占的百分比的时间。
一个时间功能对象的数组(CAMediaTimingFunction),用来指定每帧动画的时间步调。这个区域会使用一个预设的值来指定,例如kCAMediaTimingFunctionEaseIn,动画出来时慢,然后加速。
关键帧动画真的相当的简单。首先,你需要考虑的是,成功的使用关键帧动画,你需要做的基本步骤:
1.决定你想要做动画的属性(例如,框架,背景,锚点,位置,边框,等等)
2.在动画对象值的区域中,指定开始,结束,和中间的值。这些都是你的关键帧(看清单4-2)
3.使用duration这个字段指定动画的时间
4.通常来讲,通过使用times这个字段,来给每帧动画指定一个时间。如果你没有指定这些,核心动画就会通过你在values这个字段指定的值分割出时间段。
5.通常,指定时间功能来控制步调。
这些都是你需要做的。你创建你的动画和增加他们到层中。调用-addAnimation就开始了动画。
关键帧动画的时间:
[animation setCalculationMode:kCAAnimationLinear]; [animation setKeyTimes: [NSArray arrayWithObjects: [NSNumbernumberWithFloat:0.0], [NSNumbernumberWithFloat:0.25], [NSNumber numberWithFloat:0.50], [NSNumbernumberWithFloat:0.75], [NSNumbernumberWithFloat:1.0],nil]];
CAAnimationGroup *animGroup = [CAAnimationGroup animation]; animGroup.animations = [NSArray arrayWithObjects:moveAnim,scaleAnim,opacityAnim, nil]; animGroup.duration = 1; [view.layer addAnimation:animGroup forKey:nil];
隐式动画:
/假设layer当前position为(100.0,100.0) theLayer.position=CGPointMake(500.0,500.0);
显式动画:
CABasicAnimation *theAnimation;theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; theAnimation.duration=3.0; theAnimation.repeatCount=2; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; theAnimation.toValue=[NSNumber numberWithFloat:0.0]; [theLayer addAnimation:theAnimation forKey:@"animateOpacity"];
CALayer:
CALayer是个简单的类,它是用来在屏幕上显示内容展示的矩形区域。每个UIView都有一个根CALayer,UIView在这个layer上描绘东西。
CALayer *myLayer = myView.layer; //先添加QuartzCore库,才能使用CALayer。 myLayer.backgroundColor = [UIColor orangeColor].CGColor; myLayer.cornerRadius = 20.0; CALayer *sublayer = [CALayer layer]; sublayer.backgroundColor = [UIColor purpleColor].CGColor; sublayer.shadowOffset = CGSizeMake(0, 3); sublayer.shadowRadius = 5.0; sublayer.shadowColor = [UIColor blackColor].CGColor; sublayer.shadowOpacity = 0.8; sublayer.frame = CGRectMake(30, 30, 128, 192); [self.view.layer addSublayer:sublayer]; CALayer *sublayer = [CALayer layer]; CALayer *imageLayer = [CALayer layer]; imageLayer.frame = sublayer.bounds; imageLayer.cornerRadius = 10.0; imageLayer.contents = (id)[UIImage imageNamed:@"snaguosha.png"].CGImage; imageLayer.masksToBounds = YES; [sublayer addSublayer:imageLayer];
CABasicAnimation animationWithKeyPath 一些规定的值:
废话说的有点多,以下是常用的动画:
1、按路径移动:
[self.imageView.layer addAnimation:self.pathAnimation forKey:nil];- (CAAnimation*)pathAnimation; {CGMutablePathRef path = CGPathCreateMutable();CGPathMoveToPoint(path,NULL,50.0,120.0);CGPathAddLineToPoint(path, NULL, 300, 488); // CGPathAddCurveToPoint(path,NULL,50.0,275.0,150.0,275.0,150.0,120.0); // CGPathAddCurveToPoint(path,NULL,150.0,275.0,250.0,275.0,250.0,120.0); // CGPathAddCurveToPoint(path,NULL,250.0,275.0,350.0,275.0,350.0,120.0); // CGPathAddCurveToPoint(path,NULL,350.0,275.0,450.0,275.0,450.0,120.0);CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];[animation setPath:path];[animation setDuration:3.0]; // [animation setAutoreverses:YES]; CFRelease(path);return animation; }
- (CAAnimation*)valuesAnimation; {CGPoint pt0 = CGPointMake(50.0, 120.0);CGPoint pt1 = CGPointMake(50.0, 275.0);CGPoint pt2 = CGPointMake(150.0, 275.0);CGPoint pt3 = CGPointMake(150.0, 120.0);CGPoint pt4 = CGPointMake(150.0, 275.0);CGPoint pt5 = CGPointMake(250.0, 275.0);CGPoint pt6 = CGPointMake(250.0, 120.0);CGPoint pt7 = CGPointMake(250.0, 275.0);CGPoint pt8 = CGPointMake(350.0, 275.0);CGPoint pt9 = CGPointMake(350.0, 120.0);CGPoint pt10 = CGPointMake(350.0, 275.0);CGPoint pt11 = CGPointMake(450.0, 275.0);CGPoint pt12 = CGPointMake(450.0, 120.0);NSArray *values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:pt0],[NSValue valueWithCGPoint:pt1],[NSValue valueWithCGPoint:pt2],[NSValue valueWithCGPoint:pt3],[NSValue valueWithCGPoint:pt4],[NSValue valueWithCGPoint:pt5],[NSValue valueWithCGPoint:pt6],[NSValue valueWithCGPoint:pt7],[NSValue valueWithCGPoint:pt8],[NSValue valueWithCGPoint:pt9],nil];CAKeyframeAnimation*animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; [animation setValues:values]; [animation setDuration:3.0]; [animation setAutoreverses:YES]; return animation; }[self.imageView.layer addAnimation:self.valuesAnimation forKey:nil];
2、缩放:
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//x,y轴缩小到0.1,Z 轴不变scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];scaleAnim.removedOnCompletion = YES;[self.imageView.layer addAnimation:scaleAnim forKey:nil];
3、透明度变化:
//透明度变化CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];opacityAnim.toValue = [NSNumber numberWithFloat:0.1];opacityAnim.removedOnCompletion = YES;opacityAnim.duration = 3.0f;[self.imageView.layer addAnimation:opacityAnim forKey:nil];
4、组合:
CAAnimationGroup *animGroup = [CAAnimationGroup animation];animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim,opacityAnim, nil];animGroup.duration = 1;[self.imageView.layer addAnimation:opacityAnim forKey:nil];
5、旋转:
CABasicAnimation *TransformAnim = [CABasicAnimation animationWithKeyPath:@"transform"];TransformAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];//沿Z轴旋转TransformAnim.toValue = [NSValue valueWithCATransform3D: CATransform3DMakeRotation(M_PI,0,0,1)];TransformAnim.cumulative = YES;TransformAnim.duration =3;//旋转2遍,360度TransformAnim.repeatCount =2;[self.imageView.layer addAnimation:TransformAnim forKey:nil];
转载于:https://www.cnblogs.com/shangdahao/archive/2013/03/17/2964261.html
ios系统框架一: Core Animation相关推荐
- 移动周刊第 182 期:谈 Android 开发技巧、 iOS 系统框架实践
写在前面 移动周刊第 182 期如约而至.如果你有好的文章以及优化建议,请发送邮件至mobilehub@csdn.net,在技术探索的道路上我们共同进步. YouTube 推出 VR 视频和 360 ...
- [iOS]-系统框架
虽说不使用系统框架也能编写 Objective-C代码,但几乎没人这么做.即便是NSObject 这个标准的根类,也属于Foundation框架,而非语言本身.若不使用Foundation,就必须自己 ...
- iOS Instrument使用之Core Animation(图形性能)
Core Animation图形性能 Debug Options 1Color Blended Layers 图层混合 2 Color Hits Green and Misses Red 图层缓存 3 ...
- iOS系统架构及iPhone应用程序框架
1.iOS介绍 2.Framework介绍3.iOS系统架构及iPhone应⽤用程序框架 4.iOS UItouch 及触摸事件与⼿手势 iOS介绍 1. iOS 操作系统是 iPhone. iPod ...
- iOS开发:Core Animation编程指南
关于Core Animation Core Animation是iOS与OS X平台上负责图形渲染与动画的基础设施.Core Animation可以动画视图和其他的可视元素.Core Animatio ...
- IOS动画(Core Animation)总结 (参考多方文章)
一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的 ...
- iOS动画集锦(Core Animation)
iOS 动画主要是指 Core Animation 框架, Core Animation是 iOS 和 OS X 平台上负责图形渲染与动画的基础框架.Core Animation 可以作用于动画视图或 ...
- 移动开发(IOS) – iOS系统架构
移动开发(IOS) – iOS系统架构 1.iOS系统架构的四个层次 1.1.可触摸层(Cocoa Touch):为应用程序开发提供各种有用的框架,并且大部分均与用户界面有关,本质上来说它负责用户在i ...
- 绘图、Core Animation与硬件架构
原文地址:http://blog.csdn.net/wzzvictory/article/details/11180241 转载请注明出处 如果觉得文章对你有所帮助,请通过留言或关注微信公众帐号wan ...
- iOS - Core Animation 核心动画
1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...
最新文章
- (亲测可行)ubuntu16.04+Opencv3.4.3+opencv_contrib3.4.3安装编译全过程
- C# 多线程 参数传递
- Mysql HA实现MYSQL的高可用
- lisp 焊接符号标注_焊接符号标注大全
- 每天一道LeetCode-----根据先序遍历和中序遍历还原二叉树
- numpy的通用函数:快速的元素级数组函数
- 对linux课程的体会和看法,我的linux体会和看法
- win7 计算机定时关机脚本,win7定时关机设置及命令
- excel的表格数据转为数据库的dbf文件
- sqlplus连mysql库_sqlplus连接数据库
- codeblock图形界面编程(二)
- 黑客工具包ShadowBrokers浅析
- 超频到3200最佳时序_10900K内存搭配超频测试,七彩虹CVN捍卫者内存颜值标杆
- 混合现实VR Twitch视频
- 阿里云的认证多少分通过?没通过可以补考吗?
- kettle实例-高级转换-数据合并
- php下雨效果源码,ps下雨效果制作步骤
- COPY NAV导航网格寻路(4) -- 生成nav网格
- Python文件操作-shutil 模块(参考)
- 计算机课教学常规要求,职业学校计算机专业常规课堂教学模式探究
热门文章
- 并行算法:如何利用并行处理提高算法的执行效率?
- 未找到依赖项 ‘org.apache.spark:spark-hive_2.11:2.4.5‘
- Linux内核开发_将Linux内核打包成img文件
- 如何利用开源风控系统 TH-Nubula(星云)防止撞库?
- 比特币现金和ICO 及其他6个加密在泰国获准交易
- PHP程序员面临的成长瓶颈
- linux 更新软件源
- 获得微软最有影响力开发者
- T-SQL语言(一)
- CentOS7下让Asp.Net Core的网站自动运行