在iOS中,整个view都是直接构建在Core Animation层之上。每个UIView实例都带有一个CALayer实例,用来管理布局属性,即所有用户可见的部分,都是由CALayer来提供的,而UIView只是封装了CALayer,在它之上添加了响应事件的能力。
CALayer坐标系统
在layer中,有以下四种属性:bounds、frame、anchorPoint、position,他们的关系如下图:
bounds是用来表示layer内部坐标位置的,frame是相对于父layer的位置,若它为view的第一层layer,那么这个位置是相对于父view的。anchorPoint是用来影响变形动画的一个值,在view的左上角为(0, 0),右下角为(1, 1),默认为(0.5, 0.5),在view的中心。变形动画,比如旋转,会绕着这个点来进行。position是anchorPoint的位置,如果layer不动,anchorPoint的值改变,也会改变position的位置。
不同类型的layer
Core Animation定义了许多种不同的layer,上表中的每种layer都继承自CALayer类,在view中默认提供的layer即CALayer,可以通过继承UIView并重写layerClass方法来定义不同的layer,当然,也可以通过添加sublayer来在UIView中增加其它种类的layer。
给layer添加动画
layer动画分为显式动画和隐式动画两种,显式动画通过生成一个CAAnimation类,显式的添加到layer上来实现,隐式动画通过直接给layer的属性赋值来实现,比如:
theLayer.opacity = 0.0;
这就声明了一个隐式动画,默认的动画时长为0.25秒。
显式动画可以定义动画的路径、开始值、结束值、持续时间、重复次数等,生成的实例添加到layer上就开始执行动画。动画在结束后返回layer的原状态,可以在addAnimation之后修改layer的属性来让它保持动画结束的状态,或者变换其他状态。也可以用CAKeyFrameAnimation来实现指定路径的动画:
不同的动画可以组合成一个CAAnimationGroup,可以同时执行,实现复杂的动画,比如在大小改变的同时改变颜色等。CAAnimation也可以设置delegate,用来在动画开始和结束时回调。
相关推荐
很棒的一本关于iOS Core Animation的书,解决了我之前对UI,动画,性能的疑惑。
CoreAnimation, this is about core animation cookbook, OG
Core AnimationCore Animation
iOS Core Animation Advanced Techniques
里面使用CoreAnimation实现各种动画, 适用初学aniamtion者
iOS Core Animation
苹果官网文档,Core Animation 是一种能让您制作高级动画和视觉效果的技术。UIKit 提供的动画,是建立在 Core Animation 技术之上的。如果您需要超出 UIKit 功能的高级动画,可以直接使用 Core Animation。
Core Animation 中&英文版本。如有侵权,联系删除! 中文翻译github地址:https://github.com/AttackOnDobby/iOS-Core-Animation-Advanced-Techniques
Core Animation for Mac OS X and the iPhone Creating Compelling Dynamic User Interfaces Our Pragmatic courses, workshops, and other products can help you and your team create better software and have ...
Addison-Wesley - Core Animation Dec 2009 Core Animation: Simplified Animation Techniques for Mac and iPhone Development Apple’s Core Animation framework enables Mac OS X, iPhone, and iPod touch ...
Core Animation for Mac OS X and the iPhone 英文版
iOS-CoreAnimation,包含CABasicAnimation、CAKeyFrameAnimation、CAAnimationGroup 、CATransition的具体实现
Core Animation Programming guide 1-5 (2) 不要下载 这个资源有错误
iOS Core Animation Advanced Techniques 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请...
本书翻译自iOS-Core-Animation-Advanced-Techniques。涉及到iOS图层,动画,性能,效果等。
core animation cook bookcore animation cook bookcore animation cook bookcore animation cook bookcore animation cook book
iOS CoreAnimation之CABasicAnimation:文字路径动画
Core Animation Programming guide 1 -5 (3) 不要下载 这个资源有错误
很棒的一本关于iOS Core Animation的书,解决了我之前对UI,动画,性能的疑惑。英文版。
IOS动画Core Animation例子,有注释。