一.了解CoreAnimation
中心动画的内部完成架构, 是根据OpenGL/OpenGL ES, Core Graphics/ Metal 基础上封装的, OpenGL/OpenGL ES, Core Graphics/ Metal运用成本都很高,苹果未来更好的让开发者做出好的动画效果,封装出CoreAnimation


二 Core Animation Introduction
- 简略易易⽤用的⾼高功能混合编程模型\
- ⽤用类似于视图⼀相同,使⽤用图层来创立复杂的编程接⼝口
- 轻量量化的数据结构,它能够同时显现让上百个图层产⽣生动画效果
- 一套⾮十分较简略的动画接⼝口,能让动画运⾏行行在独⽴立的线程中,并能够独⽴立于主线程之外.
- 一旦动画装备完成并启动,核⼼心动画就能独⽴立并彻底操控相应的动画帧.
- 提⾼高应⽤用功能.应⽤用程序只有当发⽣生改变的时候才会重绘内容.使⽤用Core Animation能够不不使⽤用其他图形API,例例如OpenGL来获取⾼高效的动画功能.
- 灵敏的布局管理理模型,答应图层相对同级图层的联系来设置特点的方位和⼤大⼩小
三 Core Animation分类

what’s the UIView ? what’s the CALayer ? 为什么要将UIView与CALayer提供2个平级层级联系
答:

为何开发者需要运用CALayer
答:

四: Core Animation Class

图层几何



五: CALayer常用特点
- Hit Testing Hit Test底层完成思路
- 常见的视图不相应事件情况




运用场景:

本类中完成

- contents 设置view背景
self.view.layer.contents = (__bridge id)image.CGImage;
self.view.contentMode // 能够设置图片显现形式
- contentsScale
self.view.layer.contentsScale = [UIScreen mainScreen].scale
/// 会影响图片显现的清晰度
六 : 动画实例
隐式动画: blog.csdn.net/u013248706/… 设置非相关layer的背景颜色,apha等,回发生隐式动画 ,默许0.25s UIVview的layer是相关的,默许隐式动画封闭 非相关便是单独创立的layer
//动画2
//begin a new transaction
[CATransaction begin];
//set the animation duration to 2 second
[CATransaction setAnimationDuration:2.0];
_layer.backgroundColor = [UIColor orangeColor].CGColor;
[CATransaction commit];
显现动画
//动画1
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.y";
animation.toValue = @600;
animation.duration = 1;
//处理动画康复到初始方位
animation.removedOnCompletion = **NO**;
animation.fillMode = kCAFillModeForwards;
[_redView.layer addAnimation:animation forKey:**nil**];

CALayer宗族

代码
#import "ViewController.h"
/*
动画增加步骤:
1.找演员CALayer,确定动画主角
2.写剧本CAAnimation,规则动画怎么样改换
3.开拍AddAnimation,开始履行
*/
**@interface** ViewController ()
**@property** (**weak**, **nonatomic**) **IBOutlet** UIView *redView;
**@property** (**nonatomic**,**strong**) CALayer *layer;
**@property** (**nonatomic**,**strong**) UIView *layer3;
\
**@end**
\
**@implementation** ViewController
\
- (**void**)viewDidLoad {
[**super** viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(100, 100, 100, 100);
layer.backgroundColor = [UIColor greenColor].CGColor;
_layer = layer;
[**self**.view.layer addSublayer:layer];
\
_layer3 = [UIView new];
_layer3.frame = CGRectMake(150, 100, 100, 100);
_layer3.backgroundColor = [UIColor yellowColor];
// _layer3.layer.zPosition = -2.0;
[**self**.view addSubview:_layer3];
}
\
- (**void**)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
_layer3.layer.zPosition = -2.0;
//动画1
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.y";
animation.toValue = @600;
animation.duration = 1;
\
//处理动画康复到初始方位
animation.removedOnCompletion = **NO**;
animation.fillMode = kCAFillModeForwards;
[_redView.layer addAnimation:animation forKey:**nil**];
//动画2
//begin a new transaction
[CATransaction begin];
//set the animation duration to 1 second
[CATransaction setAnimationDuration:2.0];
_layer.backgroundColor = [UIColor orangeColor].CGColor;
[CATransaction setCompletionBlock:^{
//rotate the layer 90 degrees
CGAffineTransform transform = **self**.layer.affineTransform;
transform = CGAffineTransformRotate(transform, M_PI_2 * 0.5);
**self**.layer.affineTransform = transform;
}];
// //commit the transaction
[CATransaction commit];
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。