随笔《Clione的电灯的光》整顿电视动漫,前年十一月开始播放!动漫大旨曲由aki担当演唱,别的还会有一张宣传图公开。别的音信暂未发布。

在上一篇中大家商量了layer的隐式动漫,隐式动漫是三个很棒的兑现layer层幼功动漫的办法,不过它并不能够落到实处layer层的基本点帧动漫和联网动漫,所以本篇将学习layer的显式动漫,显式动漫可分为:特性动画(底蕴动漫和重要性帧动画)、动画组连片动漫

问:怎么评价动漫工房? 怎么评价动漫工房

其次篇隐式动漫大家提起隐式动漫能够直接效果于layer的可动漫属性,然而不可能一贯效果于UIView关联的相当layer的可动漫属性,因为UIKit框架把UIView关联的layer的隐式动漫给禁止使用了。而显式动漫就分化样了,显式动画也是魔法于layer层的,可是它不只能够成效于直接创建的layer,也可以作用于view关联的layer,所以我们就无需区分了,直接怼layer就能够了。

图片 1


动漫工房,这家东瀛名高天下的动漫片制作公司,相信看扶桑卡通有个别年头的动画爱好者们料定是相比较熟谙的。动漫工房,作为一家肩负动漫企划以至动漫制作的店铺,其实在上世纪70年间末,80年间的扶桑动漫业界,就早就有动漫工房活跃的人影了。别的动画创作不说,光是宫崎骏执导,吉卜力动画工作室制作的动漫电影,动漫工房就以外包的情态,到场到《风之谷》以至《天空之城》动漫电影的动漫协力部分

目录

当今,动漫工房已经济体改为了一家以创设萌系美女郎日常动漫专精的日本动漫制作集团,所以说,当下活跃于日本动漫产业界的一对一一些“猛男番”,就是来自动漫工房之手。如若各位小伙们是特别爱怜看萌萌可爱的美女郎们张开种种平时生活的卡通片,那就必定将要选准动漫工房这家公司了。在部分一定一级的萌系美女郎日常动漫制作方面,其实动画工房的显现并不如京都动漫差哦。

一、属性动漫(CAPropertyAnimation)

好似是在二零零六年间在此之前,动漫工房这家东瀛动漫制作集团并从未鲜明性其创设动漫的优势,在有力量独立制作动漫之后,并非只变成别的元请动漫制作公司的外包的卡通工房,就出产了一丰富多彩的动画作品,比较刚开始阶段的时候,动漫工房这家集团入眼以游戏剧修改编动漫为主,动漫工房从前是创制过GALGAME名作《秋之纪念》种类第五部的动漫。

1、幼功动漫(CABasicAnimation)

但是呢,以娱乐整编动漫为根本发展道路的动漫工房,如同并从未中标,之前动漫工房所制作的一俯拾都已经游戏剧改善编动画,在扶桑动漫片观者以致境内动漫客官的心里中,评价并非异常高,也正是平时的程度。毕竟东瀛动漫产业界的竞争也是很凶猛的,想要相比好地开辟进取下去,就亟必要研究出一条任何卡通制作集团不太好模仿,丰富发挥自个儿人力财富等优势的道路。而动漫片工房在步入到2013年之后,真的就根究出了那样一条道路,那正是专精于萌系美青娥平时动漫或然恋爱好笑喜剧动漫

(1)什么是根底动漫?

二零一三年,一部名称为《摇动百合》的卡通平地而起,对于喜美观萌系美女郎经常动漫的观者来讲,由动漫工房制作的《摆荡百合》动漫无疑是很优良的,可爱并且天性特征显然的美女郎剧中人物,轻巧滑稽的剧情管理,还应该有不俗的家常动漫演出甚至可看性很强的神情演技作画,卡通工房靠着《挥舞百合》打响了其专精萌系美青娥平常动漫的名称

(2)如何行使底蕴动漫?

除了这一个之外专精于萌系美少女平时动漫以外,动漫工房还十分长于制作恋爱正剧动画,当中的代表作相对正是《月刊青娥野崎君》,观察过那部动漫片的观众们基本上都会以为那是一部能够笑出腹内斜肌的恋爱正剧动漫,并且动漫中的女一号佐仓千代的颜艺表情特别常有看点

(3)举个例子表明底蕴动漫须求专心的多个地点及缓和

于是,动漫工房就平素本着那条科学的道路走下来了,《NEW
GAME》
动漫片种类,上一季的突兀动漫之一《Smart光降到了自己身边》,都在东瀛以致境内的动漫圈引起了非常大的震撼。假使各位小同伙们因为学习只怕工作而正如疲惫时,当想看看比较轻便风趣的经常动漫,那就请认准动漫工房,那是一家能够让猛男也落泪的厂商

2、关键帧动漫(CAKeyframeAnimation)

关怀【拾部次元】,多个由漫画师撰写,有态度的动画频道

(1)什么是第一帧动漫?

谢谢诚邀,请问怎么是动漫工房?作者不了解动漫工房的绘身绘色规范内容,回答不了那一个主题素材,还望海涵。

(2)怎么样接纳首要帧动漫?

动漫能样大家知道一些知识

(3)比如表明设置关键帧的五个措施:数组关键帧法和门路关键帧法

百合工房 萝莉工房 猛男非看不可(๑•̀ㅂ•́卡塔尔国و✧

二、动画组(CAAnimationGroup)

(1)什么是动漫组?
(2)怎样行使动漫组?

三、过渡动画

(1)什么是过渡动漫?
(2)怎么着选取过渡动漫?

四、什么情况下行使突显动漫


一、属性动漫(CAPropertyAnimation)

小编们明白想要做属性动漫的话,能够一向利用UIView的block属性动漫,也足以采纳layer的隐式动漫来落成,那么这里的layer呈现动漫的天性动漫正是咱们完成属性动漫的第二种接受。

品质动漫又有三个子类,大家平时主要使用那五个子类来做动漫,它们是底子动漫(CABasicAnimation)言行一致帧动漫(CAKeyframeAnimation),接下去大家将分头介绍:

1、功底动漫(CABasicAnimation)
(1)什么是底蕴动漫?

先是篇中UIView block根底动漫说过了,相同。

(2)如何运用底工动漫?

根基动漫的运用也非常轻易,只需求按以下7个步骤来就能够了:

  • 创制多个底子动漫
  • 设置好基本功动漫的代理(回调中要办事的)
  • 点名底工动漫要更动的性质
  • 给幼功动漫一个开头值(不给也行,会默以为layer初步状态对应属性的值)
  • 给根基动画二个截止值
  • 再钦定一些功底动画的此外设置(如动漫时长、重复次数等)
  • 接下来把这么些底子动漫增多到layer上,动漫就能够最早进行了
(3)举例

给customLayer背景观的变越发二个动漫,给customLayer1切圆角的改动加三个动漫片

(清单3.1)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) CALayer *customLayer;
@property (strong, nonatomic) CALayer *customLayer1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customLayer = [[CALayer alloc] init];
    self.customLayer.frame = CGRectMake(100, 100, 100, 100);
    self.customLayer.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer];

    self.customLayer1 = [[CALayer alloc] init];
    self.customLayer1.frame = CGRectMake(100, 250, 100, 100);
    self.customLayer1.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer1];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CABasicAnimation *basicAnimation = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer背景色basicAnimation===%@", basicAnimation);
    basicAnimation.delegate = self;
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.toValue = (__bridge id _Nullable)([UIColor orangeColor].CGColor));
    basicAnimation.duration = 3;
    [self.customLayer addAnimation:basicAnimation forKey:nil];

    CABasicAnimation *basicAnimation1 = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer1切圆角basicAnimation1===%@", basicAnimation1);
    basicAnimation1.delegate = self;
    basicAnimation1.keyPath = @"cornerRadius";
    basicAnimation1.toValue = @(50);
    basicAnimation1.duration = 3;
    [self.customLayer1 addAnimation:basicAnimation1 forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了===%@", anim);
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    NSLog(@"动画结束了===%@", anim);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

图片 2

1.gif

运作,大家能够看出确实有了动漫片,可是也开掘了之类难点:

  • 卡通在成就未来又跳回到早先状态了,那是为什么?
    • 本着那一个难题:其实底蕴动漫只是虚构出来的视觉效果,并未当真转移layer做动漫那叁个属性的值,所以大家要在动漫甘休把layer做动漫的特别属性的值矫正为动漫片的完工值。同一时候大家要专一在动漫截至重新安装layer属性值的时候,要记得关闭layer的隐式动漫,不然既会有基础动漫带给的动漫片也许有隐式动漫带给的卡通,就重叠了。改进动画结束的代办方法如下:

(清单3.2)

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    NSLog(@"动画结束了===%@", anim);

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.customLayer.backgroundColor = [UIColor orangeColor].CGColor;
    self.customLayer1.cornerRadius = 50;
    [CATransaction commit];
}

图片 3

1.gif

运行,开掘可以了,可是又开掘七个难点:

  • 退换layer属性值的时候,layer赶快地闪回到起初状态才成为截止值,那是为什么?(模拟器是还未难题的,所以调试动漫一定要在真机上整)

    • 针对这么些标题:大家供给在动漫截至今后,设置layer保持哪一帧,须要安装为保全动漫结束后的那一帧,並且从前设置动漫甘休后不活动移除,而是在要求的时候手动移除。通过那八个属性的设置(即animationremovedOnCompletionfillMode两特性子),动漫在得了时就不会相当的慢闪回带头状态再形成结束状态了,代码如下:

(清单3.3)

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CABasicAnimation *basicAnimation = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer背景色basicAnimation===%@", basicAnimation);
    basicAnimation.delegate = self;
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.toValue = (__bridge id _Nullable)([UIColor orangeColor].CGColor);
    basicAnimation.duration = 3;
    basicAnimation.removedOnCompletion = NO;// 动画结束后不自动移除动画
    basicAnimation.fillMode = kCAFillModeForwards;// 动画结束后保持结束时的那一帧
    [self.customLayer addAnimation:basicAnimation forKey:nil];

    CABasicAnimation *basicAnimation1 = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer1切圆角basicAnimation1===%@", basicAnimation1);
    basicAnimation1.delegate = self;
    basicAnimation1.keyPath = @"cornerRadius";
    basicAnimation1.toValue = @(50);
    basicAnimation1.duration = 3;
    basicAnimation1.removedOnCompletion = NO;
    basicAnimation1.fillMode = kCAFillModeForwards;
    [self.customLayer1 addAnimation:basicAnimation1 forKey:nil];
}
  • 还大概有三个难点不怕,比如大家在三个调整器里面创造了多少个卡通的话(比方(项目清单3.1)中大家分别给customLayer和customLayer1创制了多个动漫),那么那七个卡通都会走到同三个动画片甘休的代办方法里,我们想要达到的卡通片指标是customLayer的卡通片结束时改换customLayer的背景观,customLayer1的动漫片甘休时更改customLayer1的圆角,并不是(清单3.1)中这种把customLayer和customLayer1两个同时退换,那如何做吧?有二种方式,我们独家看一下:

    • 主意一:我们看见动漫甘休的代理方法是有个参数anim把动漫带回去的,那是或不是我们得以把我们创设的卡通片创产生属性,来那边比对,对上号之后改正相应layer的天性不就足以了嘛。看似异常的粗略完美的主意。不过你也来看大家有打印操作了,看下调控台的出口吧:

(清单3.3)

2018-01-16 11:06:09.205151+0800 CoreAnimation[1582:390479] customLayer背景色basicAnimation===<CABasicAnimation: 0x1c803aa40>
2018-01-16 11:06:09.205444+0800 CoreAnimation[1582:390479] customLayer1切圆角basicAnimation1===<CABasicAnimation: 0x1c803ab20>
2018-01-16 11:06:09.205989+0800 CoreAnimation[1582:390479] 动画开始了===<CABasicAnimation: 0x1c803ab40>
2018-01-16 11:06:09.206101+0800 CoreAnimation[1582:390479] 动画开始了===<CABasicAnimation: 0x1c803ab00>
2018-01-16 11:06:12.207372+0800 CoreAnimation[1582:390479] 动画结束了===<CABasicAnimation: 0x1c803ab40>
2018-01-16 11:06:12.207838+0800 CoreAnimation[1582:390479] 动画结束了===<CABasicAnimation: 0x1c803ab00>

咱俩惊讶地意识,咱俩创设的底工动漫和卡通片开头、停止代理方法带回来的动漫片并不是多少个卡通。因为动漫初阶、甘休代理方法带回到的动漫是大家创设的底子动漫的深拷贝,omg,这种情势战败了。

  • 主意二:回到(清单3.1)能够看见,大家在给layer加多动漫的办法-addAnimation: forKey:的key我们给的是空,其实大家能够在这里个地点给animation关联多个key,那个key其实便是咱们能取获得内定animation的独一标识。大家修正代码如下:

(清单3.4)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) CALayer *customLayer;
@property (strong, nonatomic) CALayer *customLayer1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customLayer = [[CALayer alloc] init];
    self.customLayer.frame = CGRectMake(100, 100, 100, 100);
    self.customLayer.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer];

    self.customLayer1 = [[CALayer alloc] init];
    self.customLayer1.frame = CGRectMake(100, 250, 100, 100);
    self.customLayer1.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer1];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CABasicAnimation *basicAnimation = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer背景色basicAnimation===%@", basicAnimation);
    basicAnimation.delegate = self;
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.toValue = (__bridge id _Nullable)([UIColor orangeColor].CGColor);
    basicAnimation.duration = 3;
    [self.customLayer addAnimation:basicAnimation forKey:@"basicAnimation"];

    CABasicAnimation *basicAnimation1 = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer1切圆角basicAnimation1===%@", basicAnimation1);
    basicAnimation1.delegate = self;
    basicAnimation1.keyPath = @"cornerRadius";
    basicAnimation1.toValue = @(50);
    basicAnimation1.duration = 3;
    [self.customLayer1 addAnimation:basicAnimation1 forKey:@"basicAnimation1"];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了===%@", anim);
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.customLayer.backgroundColor = [UIColor orangeColor].CGColor;
    self.customLayer1.cornerRadius = 50;
    [CATransaction commit];

    NSLog(@"动画结束了===%@, %@", [self.customLayer animationForKey:@"basicAnimation"], self.customLayer1.animationKeys);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

但是运维,发掘输出都是空,不明了干什么?待解。

(清单3.5)

2018-01-16 13:12:46.985628+0800 CoreAnimation[1695:434274] customLayer背景色basicAnimation===<CABasicAnimation: 0x1c803e280>
2018-01-16 13:12:46.986083+0800 CoreAnimation[1695:434274] customLayer1切圆角basicAnimation1===<CABasicAnimation: 0x1c803e360>
2018-01-16 13:12:46.986961+0800 CoreAnimation[1695:434274] 动画开始了===<CABasicAnimation: 0x1c803e380>
2018-01-16 13:12:46.987066+0800 CoreAnimation[1695:434274] 动画开始了===<CABasicAnimation: 0x1c803e340>
2018-01-16 13:12:49.988287+0800 CoreAnimation[1695:434274] 动画结束了===(null), (null)
2018-01-16 13:12:49.988567+0800 CoreAnimation[1695:434274] 动画结束了===(null), (null)
  • 形式三:幸运的是,大家还应该有第二种方法。正是Core
    Animation完成了KVC,所以能够随意给一个卡通贴标签,並且key和value都是id类型的
    ,所以那边我们就足以吧layer作为value给基本功动漫贴个标签,然后再动漫结束的回调里就足以判明出切实可行是哪些动漫结束了。修改代码如下:

(清单3.6)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) CALayer *customLayer;
@property (strong, nonatomic) CALayer *customLayer1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customLayer = [[CALayer alloc] init];
    self.customLayer.frame = CGRectMake(100, 100, 100, 100);
    self.customLayer.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer];

    self.customLayer1 = [[CALayer alloc] init];
    self.customLayer1.frame = CGRectMake(100, 250, 100, 100);
    self.customLayer1.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer1];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CABasicAnimation *basicAnimation = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer背景色basicAnimation===%@", basicAnimation);
    basicAnimation.delegate = self;
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.toValue = (__bridge id _Nullable)([UIColor orangeColor].CGColor);
    basicAnimation.duration = 3;
    [basicAnimation setValue:self.customLayer forKey:@"tag"];
    [self.customLayer addAnimation:basicAnimation forKey:nil];

    CABasicAnimation *basicAnimation1 = [[CABasicAnimation alloc] init];
    NSLog(@"customLayer1切圆角basicAnimation1===%@", basicAnimation1);
    basicAnimation1.delegate = self;
    basicAnimation1.keyPath = @"cornerRadius";
    basicAnimation1.toValue = @(50);
    basicAnimation1.duration = 3;
    [basicAnimation1 setValue:self.customLayer1 forKey:@"tag"];
    [self.customLayer1 addAnimation:basicAnimation1 forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了===%@", anim);
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    if ([anim valueForKey:@"tag"] == self.customLayer) {

        [CATransaction begin];
        [CATransaction setDisableActions:YES];
        self.customLayer.backgroundColor = [UIColor orangeColor].CGColor;
        [CATransaction commit];
    }

    if ([anim valueForKey:@"tag"] == self.customLayer1) {

        [CATransaction begin];
        [CATransaction setDisableActions:YES];
        self.customLayer1.cornerRadius = 50;
        [CATransaction commit];
    }

    NSLog(@"动画结束了===%@, %@", [self.customLayer animationForKey:@"basicAnimation"], self.customLayer1.animationKeys);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
2、关键帧动漫(CAKeyframeAnimation)
(1)什么是重要帧动漫?

重在帧动漫雷同也是性质动画的叁个子类,它也是用来做layer层的品质动漫的,它可以用来做一些相比复杂的性质动画。举例说,大家看见底子动漫的几个弊放正是它只要求给五个起始值和得了值就足以了,这样的意义在水田下就展现平板以至不能够知足要求。而重大帧动漫就足以帮助我们脱位基本功动画仅仅是早先值和甘休值的限制,能够专擅安装再三再四串关键帧,以致是绘制曲线。

(2)如何运用重要帧动漫?

重大帧动漫的采纳也相当粗略,只要求按以下7个步骤来就足以了:

  • 创立一个人命关天帧动漫
  • 设置好重大帧动漫的代办(回调中要干活的)
  • 钦定关键帧动漫要改成的性质
  • 给关键帧动漫的values属性设置一写关键帧(注意第一帧无法大致,它不会默感觉layer早先状态的属性值,第一帧我们要积极设置为layer开首状态的属性值,不然会从上马状态的值直接跳变到第一帧)的数组也许路径绘制设置首要帧法
  • 再钦点一些底蕴动漫的其余设置(如动漫时间长度、重复次数等)
  • 接下来把这几个根基动漫增添到layer上,动漫就能够早先施行了
(3)例如
  • values数组关键帧法:退换customLayer的背景象
    (清单3.7)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) CALayer *customLayer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customLayer = [[CALayer alloc] init];
    self.customLayer.frame = CGRectMake(100, 100, 100, 100);
    self.customLayer.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:self.customLayer];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CAKeyframeAnimation *basicAnimation = [[CAKeyframeAnimation alloc] init];
    basicAnimation.delegate = self;
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.values = @[
                              (__bridge id _Nullable)([UIColor redColor].CGColor),// 第一帧我们要主动设置为layer初始状态的属性值
                              (__bridge id _Nullable)([UIColor orangeColor].CGColor),
                              (__bridge id _Nullable)([UIColor yellowColor].CGColor),
                              (__bridge id _Nullable)([UIColor greenColor].CGColor)
                              ];
    basicAnimation.duration = 3;
    [basicAnimation setValue:self.customLayer forKey:@"tag"];
    [self.customLayer addAnimation:basicAnimation forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.customLayer.backgroundColor = [UIColor greenColor].CGColor;
    [CATransaction commit];

    NSLog(@"动画结束了");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

图片 4

1.gif

  • 路径关键帧法:让layer沿二个三遍贝塞尔曲线移动

我们精晓UIView
block关键帧动漫只好设置数组关键帧,所以一旦有的场景下,大家须求一而再接二连三的关键帧就要求运用显式动漫的主要帧动漫了,它扶持路线关键帧。

(清单3.8)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) UIImageView *customImageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customImageView = [[UIImageView alloc] init];
    self.customImageView.frame = CGRectMake(100, 100, 100, 100);
    self.customImageView.backgroundColor = [UIColor clearColor];
    self.customImageView.image = [UIImage imageNamed:@"汽车"];
    [self.view addSubview:self.customImageView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    CAKeyframeAnimation *keyframeAnimation = [[CAKeyframeAnimation alloc] init];
    keyframeAnimation.delegate = self;
    keyframeAnimation.keyPath = @"position";

    // 绘制一个三次贝塞尔曲线
    UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
    [bezierPath moveToPoint:CGPointMake(150, 150)];
    [bezierPath addCurveToPoint:CGPointMake(150, 450) controlPoint1:CGPointMake(250, 250) controlPoint2:CGPointMake(50, 350)];
    // 绘制一个shapeLayer放在屏幕上显得更形象
    CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
    shapeLayer.path = bezierPath.CGPath;
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.strokeColor = [UIColor magentaColor].CGColor;
    shapeLayer.lineWidth = 3.0f;
    [self.view.layer addSublayer:shapeLayer];

    keyframeAnimation.path = bezierPath.CGPath;
    keyframeAnimation.duration = 3;
    keyframeAnimation.rotationMode = kCAAnimationRotateAuto;// 让layer根据曲线的切线自动旋转方向
    [keyframeAnimation setValue:self.customImageView forKey:@"tag"];
    [self.customImageView.layer addAnimation:keyframeAnimation forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.customImageView.layer.position = CGPointMake(150, 450);
    [CATransaction commit];

    NSLog(@"动画结束了");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

图片 5

1.gif

二、动画组

(1)什么是动漫组?

动漫片组其实很简单了,它是别的二个继续于CAAnimation的子类,它提供了三个animations的数组属性用来把数不清个熟识感动漫组成起来协同实行和操纵,防止一批动漫单个调整的麻烦

自然了,大家决不组合卡通而是把单个单个的动漫分别添在同四个layer上也是足以的。

(2)怎么着运用动漫组?

很简短了,创设单个单个的卡通,然后把这一个单个单个的卡通赋值给动漫组的animations数组,然后把那么些动画组增加到layer上,这一批动画就会起来还要实施了。

比喻:把地方的底工动漫和入眼帧动漫组成起来,构成动漫组。
(清单3.9)

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) CALayer *customLayer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customLayer = [[CALayer alloc] init];
    self.customLayer.frame = CGRectMake(100, 100, 100, 100);
    self.customLayer.backgroundColor = [UIColor redColor].CGColor;
    self.customLayer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"汽车"].CGImage);
    self.customLayer.contentsScale = [UIScreen mainScreen].scale;
    [self.view.layer addSublayer:self.customLayer];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 基础动画
    CABasicAnimation *basicAnimation = [[CABasicAnimation alloc] init];
    basicAnimation.keyPath = @"backgroundColor";
    basicAnimation.toValue = (__bridge id _Nullable)([UIColor orangeColor].CGColor);

    // 关键帧动画
    CAKeyframeAnimation *keyframeAnimation = [[CAKeyframeAnimation alloc] init];
    keyframeAnimation.keyPath = @"position";
    // 绘制一个三次贝塞尔曲线
    UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
    [bezierPath moveToPoint:CGPointMake(150, 150)];
    [bezierPath addCurveToPoint:CGPointMake(150, 450) controlPoint1:CGPointMake(250, 250) controlPoint2:CGPointMake(50, 350)];
    // 绘制一个shapeLayer放在屏幕上显得更形象
    CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
    shapeLayer.path = bezierPath.CGPath;
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.strokeColor = [UIColor magentaColor].CGColor;
    shapeLayer.lineWidth = 3.0f;
    [self.view.layer addSublayer:shapeLayer];
    keyframeAnimation.path = bezierPath.CGPath;
    keyframeAnimation.rotationMode = kCAAnimationRotateAuto;// 让layer根据曲线的切线自动旋转方向

    // 动画组
    CAAnimationGroup *animationGroup = [[CAAnimationGroup alloc] init];
    animationGroup.delegate = self;
    animationGroup.animations = @[basicAnimation, keyframeAnimation];
    animationGroup.duration = 3;
    [self.customLayer addAnimation:animationGroup forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.customLayer.backgroundColor = [UIColor orangeColor].CGColor;
    self.customLayer.position = CGPointMake(150, 450);
    [CATransaction commit];

    NSLog(@"动画结束了");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

图片 6

1.gif

三、过渡动漫

(1)什么是联网动漫?

率先篇说过了,相似。

紧接动漫(CATransition)同样是CAAnimation的三个子类,但它不像属性动漫那样是平整地在多个属性值之间做动画,而是直白对全体图层做改动(即过渡动漫不是针对图层的习性的,而是针对图层的,当然它能够用来做属性动漫而不囿于于做属性动画,大家以致能够在不转移图层大概不理解更动了图层什么东西的气象下直接给图层增加多少个连通动漫,也正是说过渡动漫是给图层添的卡通,只要有layer存在,我们其余机遇任何境况都能给layer增添对接动漫,能够给layer添,也得以给view关联的layer添),即首先呈现纠正前的图层外观,然后经过叁个连片动漫的意义调换成新的外观体现

(2)怎么样运用过渡动漫?
  • 成立过渡动漫
  • 安装好过渡动漫的代理
  • 设置过渡动画类型, 过渡动漫子类型, 过渡动漫卡通速度及别的一些装置
  • 安装图层的新外观
  • 把过渡动漫增添到layer上,过渡动漫就开头推行了

连接动漫类型(type):用来支配过渡动漫的功用,有下边九种:

fade// 淡入淡出的效果(没有方向)
push// 新图层从一侧推入、旧图层从一侧推出来展示新外观效果
moveIn// 新图层从一侧推入来展示新外观效果、但旧图层没有从一侧推出
reveal// 旧图层从一侧推出来展示新外观效果、但新图层没有从一侧推入
oglFlip// 正面和背面的二维翻转效果
cube// 立方体翻转效果
pageCurl// 翻页效果
suckEffect// 收缩效果
rippleEffect// 水滴波纹效果(没有方向)

连着动漫子类型如下(subType):用来调控过渡动漫的趋势,有上面各类,type里除了fade和rippleEffect未有动向之外,此外效率皆有来头

kCATransitionFromTop// 从底部开始过渡动画
kCATransitionFromLeft// 从左侧开始过渡动画
kCATransitionFromBottom// 从顶部开始过渡动画
kCATransitionFromRight// 从右侧开始过渡动画

转场动漫缓冲曲线调节(timingFunction):有下边各种

kCAMediaTimingFunctionEaseInEaseOut// 动画慢进,逐渐加快,逐渐减慢,慢出
kCAMediaTimingFunctionEaseIn// 动画慢进,逐渐加快
kCAMediaTimingFunctionEaseOut// 动画逐渐减慢,慢出
kCAMediaTimingFunctionLinear// 动画匀速

可以看到layer显式动漫的连通动漫效果要比UIView
block过渡动漫的成效多了非常多,由此效果也会更丰裕一些。

上面举个例证,近似第一篇的,切换imageView的图样和label的文本,只可是是个水纹效果:

//
//  ViewController.m
//  CoreAnimation
//
//  Created by 意一yiyi on 2017/11/13.
//  Copyright © 2017年 意一yiyi. All rights reserved.
//

#import "ViewController.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height

@interface ViewController ()<CAAnimationDelegate>

@property (strong, nonatomic) UIImageView *customImageView;
@property (strong, nonatomic) UILabel *label;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.customImageView = [[UIImageView alloc] init];
    self.customImageView.frame = CGRectMake(0, 64, kScreenWidth, kScreenWidth);
    self.customImageView.backgroundColor = [UIColor redColor];
    self.customImageView.image = [UIImage imageNamed:@"0.jpg"];
    [self.view addSubview:self.customImageView];

    self.label = [[UILabel alloc] init];
    self.label.frame = CGRectMake(0, kScreenWidth + 100, kScreenWidth, 30);
    self.label.text = @"奥黛丽·赫本";
    self.label.textColor = [UIColor blackColor];
    self.label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.label];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 创建过渡动画
    CATransition *transition = [[CATransition alloc] init];

    // 设置好过渡动画的代理
    transition.delegate = self;

    // 设置过渡动画类型、子类型、时间曲线及其它一些设置
    transition.type = @"rippleEffect";
    transition.subtype = kCATransitionFromTop;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.duration = 3;

    // 设置图层的新外观
    NSInteger num = arc4random()%7;
    self.customImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg", num]];
    switch (num) {
        case 0:
            self.label.text = @"奥黛丽·赫本";
            break;
        case 1:
            self.label.text = @"苏菲·玛索";
            break;
        case 2:
            self.label.text = @"泰勒·斯威夫特";
            break;
        case 3:
            self.label.text = @"安妮·海瑟薇";
            break;
        case 4:
            self.label.text = @"娜塔丽·波特曼";
            break;
        case 5:
            self.label.text = @"凯拉·奈特利";
            break;
        case 6:
            self.label.text = @"杰西卡·阿尔芭";
            break;
    }

    // 把过渡动画添加到layer上
    [self.customImageView.layer addAnimation:transition forKey:nil];
    [self.label.layer addAnimation:transition forKey:nil];
}

- (void)animationDidStart:(CAAnimation *)anim {

    NSLog(@"动画开始了");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    NSLog(@"动画结束了");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

图片 7

1.gif

四、什么状态下利用展现动漫

本着底工动漫:用UIView
block根底动漫和layer的隐式动漫就够了,layer的显式动漫的底蕴动漫也没多吗,用起来反而累赘。

针对重大帧动漫:平常情形下行使UIView
block关键帧动漫就能够,不过若是是亟需三番五次关键帧的光景就供给使用layer的显式动漫的最首要帧动漫。

本着过渡动漫:日常情况下行使UIView
block过渡动漫就能够,可是如若是必要更丰硕动漫效果的光景能够使用layer的显式动漫的连结动漫。

总的来说,我们一时半刻还并未有供给直接创设layer来做动漫,开采中健康用UIView就足以了,UIView
block动漫就隐蔽了,隐式动漫和体现动漫也都以能够直接或直接地成效于view关联的layer的。

相关文章