32.核心动画介绍04-27

前言:
任何复杂的动画其实都是由一个个简单的动画组装而成的,只要我们善于分解和组装,我们就能实现出满意的效果。
一、简介
iOS动画主要是指Core Animation(我们简称CA)框架。官方使用文档地址为:Core Animation Guide

二、开始解读官方文档
Core Animation is a graphics rendering and animation infrastructure available on both iOS and OS X that you use to animate the views and other visual elements of your app. With Core Animation, most of the work required to draw each frame of an animation is done for you. All you have to do is configure a few animation parameters (such as the start and end points) and tell Core Animation to start. Core Animation does the rest, handing most of the actual drawing work off to the onboard graphics hardware to accelerate the rendering. This automatic graphics acceleration results in high frame rates and smooth animations without burdening the CPU and slowing down your app.

Core Animation是iOS和macOS平台上负责图形渲染与动画的基础框架。Core Animation可以作用与动画视图或者其他可视元素,为你完成了动画所需的大部分绘帧工作。你只需要配置少量的动画参数(如开始点的位置和结束点的位置)即可使用Core Animation的动画效果。Core Animation将大部分实际的绘图任务交给了图形硬件来处理,图形硬件会加速图形渲染的速度。这种自动化的图形加速技术让动画拥有更高的帧率并且显示效果更加平滑,不会加重CPU的负担而影响程序的运行速度。

If you are writing iOS apps, you are using Core Animation whether you know it or not. And if you are writing OS X apps, you can take advantage of Core Animation with extremely little effort. Core Animation sits beneath AppKit and UIKit and is integrated tightly into the view workflows of Cocoa and Cocoa Touch. Of course, Core Animation also has interfaces that extend the capabilities exposed by your app’s views and give you more fine-grained control over your app’s animations.

如果你正在编写iOS应用程序,你可以使用的是核心动画,不管你是否知道。如果你正在编写OSX应用程序,你可以很轻易地使用核心动画。核心动画位于AppKIT和UIKit的下方,并集成到Cocoa和Cocoa Touch的视图工作流程中。当然,核心动画还具有扩展应用程序视图所显示的功能的接口,并为您的应用程序动画提供更精确的控制。


图片.png

At a Glance
You may never need to use Core Animation directly, but when you do you should understand the role that Core Animation plays as part of your app’s infrastructur
看一眼
您可能永远不需要直接使用核心动画,但是当您这样做时,您应该理解核心动画作为应用程序基础结构的一部分所起的作用。

Core Animation Manages Your App’s Content

Core Animation is not a drawing system itself. It is an infrastructure for compositing and manipulating your app’s content in hardware. At the heart of this infrastructure are layer objects, which you use to manage and manipulate your content. A layer captures your content into a bitmap that can be manipulated easily by the graphics hardware. In most apps, layers are used as a way to manage the content of views but you can also create standalone layers depending on your needs.

核心动画管理你的app的内容
核心动画本身不是绘图系统。它是在硬件中合成和操作应用程序内容的基础设施。这个基础结构的核心是层对象,用来管理和操作内容。一个图层将你的内容捕获到一个可以被图形硬件轻松操纵的位图中。在大多数应用程序中,层是用来管理视图内容的一种方式,但也可以根据您的需要创建独立的层。

Layer Modifications Trigger Animations

Most of the animations you create using Core Animation involve the modification of the layer’s properties. Like views, layer objects have a bounds rectangle, a position onscreen, an opacity, a transform, and many other visually-oriented properties that can be modified. For most of these properties, changing the property’s value results in the creation of an implicit animation whereby the layer animates from the old value to the new value. You can also explicitly animate these properties in cases where you want more control over the resulting animation behavior.

修改层,触发动画
动画你使用核心动画创建的大部分动画,都涉及修改层的属性。像views,层对象有大小,有屏幕位置,不透明度,形变,和许多其他可修改的视觉导向的属性;对于这些属性,改变这些属性值可以产生动画的创建,通过修改旧值到新值。Changing the results in the creation of an implicit动画whereby the层animates from the old value to the new value。在你想要跟多控制动画行为的情况下,你也可以明确这些属性。

Layers Can Be Organized into Hierarchies

Layers can be arranged hierarchically to create parent-child relationships. The arrangement of layers affects the visual content that they manage in a way that is similar to views. The hierarchy of a set of layers that are attached to views mirrors the corresponding view hierarchy. You can also add standalone layers into a layer hierarchy to extend the visual content of your app beyond just your views.
层可以被组织成层次结构。
层次可以分层排列,以创建父子关系。层的排列影响视觉内容的管理方式,类似于views。连接到视图的一组层的层次结构反映了相应的视图层次结构。您还可以将独立的层添加到层层次结构中,以扩展您的应用程序的视觉内容,而不仅仅是您的视图。

Actions Let You Change a Layer’s Default Behavior

Implicit layer animations are achieved using action objects, which are generic objects that implement a predefined interface. Core Animation uses action objects to implement the default set of animations normally associated with layers. You can create your own action objects to implement custom animations or use them to implement other types of behaviors too. You then assign your action object to one of the layer’s properties. When that property changes, Core Animation retrieves your action object and tells it to perform its action.
动作对象让你改变一个层的默认行为
隐式层动画是使用动作对象来实现的,这些动作对象是实现预定义接口的通用对象。核心动画使用动作对象来实现通常与层相关联的默认动画效果。您可以创建自己的动作对象来实现自定义动画,或者使用它们来实现其他类型的行为。然后,将动作对象分配给该层的属性之一。当该属性更改时,核心动画将检索您的操作对象并告诉它执行其动作。

ps:例如view缩小的动画执行万,会恢复原来的大小

How to Use This Document

This document is intended for developers who need more control over their app’s animations or who want to use layers to improve the drawing performance of their apps. This document also provides information about the integration between layers and views for both iOS and OS X. The integration between layers and views is different on iOS and OS X and understanding those differences is important to being able to create efficient animations

怎么使用这个文档
这个文档是为那些需要更多控制他们的应用程序动画或想要使用层来提高他们的应用程序的绘图性能的开发者而设计的。该文档还提供了关于IOS和OS X的层和视图之间的集成的信息。在IOS和OS X之间,层和视图之间的集成是不同的,并且理解这些差异对于能够创建高效动画是重要的。

Prerequisites

You should already understand the view architecture of your target platform and be familiar with how to create view-based animations. If not, you should read one of the following documents:
您应该已经了解了目标平台的视图体系结构,并且熟悉如何创建基于视图的动画。如果没有,你应该阅读下列文件之一:

See Also

For examples of how to implement specific types of animations using Core Animation, see Core Animation Cookbook.
也可以看下
举例说明如何使用核心动画来实现特定类型的动画,请参见核心动画CooBook。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容