Coreanimation Programming Guide (i) Core Animation basics

Source: Internet
Author: User

What is a core animation

The core animation is a graphical rendering and animation infrastructure available on iOS and OS X, which you use to animate views and other visual elements of your application. The core animation that most of the work needs to draw out every frame of animation is done for you. All you need to do is configure some animation parameters (such as start and end points) to tell the core animation to start. The core animation does not rest, putting the most practical drawing work out of the onboard graphics hardware to accelerate rendering. This automatic graphics acceleration results in high frame rate and smooth animations without adding CPU and slowing down your application .
If you're writing an iOS app, you're using a core animation whether you know it or not. If you are writing an OS X application, you can take advantage of very small effort core animations. The core animations sit on Uikit and appkit and are tightly integrated into the workflow view of cocoa and cocoa Touch. Of course, the core animations also have interfaces that extend the view of your application to the ability to expose you to more granular applications that control your animations.

Core animations provide a common system of animation views and other visual elements of the application. The core animation is a view that is not replaced for your application. Instead, it is a technology that integrates views to provide better performance and support for animated content. By caching the view as a bitmap, the contents of this behavior can be implemented by direct manipulation of the graphics hardware. In some cases, this caching behavior may require you to rethink your status quo and manage the content of your application, but most of the time you do not know it exists using the core animation. In addition to caching view content, core animations also define a way to specify arbitrary visual content, integrate content with your comments, and put it with everything.
You use the core animation animations to change the views and visuals of your application. Most of the changes involve modifying the properties of your visuals. For example, you can use the core animation animation to change the position, size, or opacity of the view. When you make such a change, the animation property of the core animation is specified between the current value and the new value. You typically do not use core animations to replace 60 times of content, such as cartoons. Instead, you use the core animation to move the contents of the view on the screen, fade or content, apply an angle to any graphical transformation, or change other visual properties of the view.

Core animations and DrawRect: the difference between

Most layers do not do any actual drawing in your application. Instead, a layer of captured content is applied to the bitmap that is provided and cached in it, and it is sometimes referred to as a storage backup. When you then change the properties of the layer, everything you do is state information about the changed Layer object. When the change triggers the animation, the animation passes through the core layer of the bitmap and the state information of the graphics hardware, and uses the new information to draw the bitmap's work. Manipulating a hardware bitmap produces animations faster than software.

Because it manipulates static bitmaps, hierarchical graphs are significantly different from traditional view-based representations. With view-based drawing, the view itself often leads to changes in the call View DrawRect: The method redraws the content using the new parameters. But this painting is expensive because it is using the main thread of the CPU. The core animation avoids this expense by using the same or similar effect as the cache bitmap in hardware implementations .

Layer-based animations

Data and status information are decoupled from the visual rendering of a layer of objects, the contents of the layer on the screen. This decoupling gives the core animations a way to intervene and animate changes from old to new state values. For example, changing the position property of a layer causes the core animation layer to move from the current position to the new specified position. Other similar changes in performance cause the corresponding animations.

During an animated process, all the frames of the core animation are drawn by the frames of your hardware. All you need to do is animate the start and end points, and let the core animations do the rest. You can also specify the need for custom timing information and animation parameters, however, the core animation also provides the appropriate default values.

Two kinds of coordinate system

The location of the content is specified using two-tier point-based coordinate systems and the cell coordinate system. The use of this coordinate system depends on the type of information being communicated. Point-based coordinates are mapped directly to screen coordinates using the specified value, or the value that must be specified relative to the other layer, such as the property cell coordinates of the layer location, should not be compared with screen coordinates for some other value. For example, a layer anchor property specifies the bounds of a point relative to the layer itself, which can be changed.
The most common use in point-based coordinates is to specify the size and position of the layer, and you use layer boundaries and position performance to define the coordinate system of the layer itself, including the screen size of the layer. This position property defines the position of the layer relative to its parent's coordinate system. Although there is a layer of frame property, property rights are actually derived from the value limits and position performance and infrequently used
The orientation bounds and frame rectangles of a layer are always the default orientation of the underlying platform. The origin of the bounding rectangle showing the bounding rectangle in iOS and OS X in iOS default direction is by default, the upper-left corner of the layer, and OS X is in the lower-left corner. If you share the core animation code between iOS and OS X versions of the application, you must consider these differences.

This diagram also shows that iOS and OS X have a different starting point for the coordinate system.

Layer Operations

Each layer has two transformation matrices that can be used to manipulate the layer and its contents. This transformation property Calayer Specifies that the layer and its embedded layer will be applied. You typically use this property when you want to modify the layer itself. For example, you can use properties to scale or rotate a layer or temporarily change its position. This Sublayertransform attribute defines additional transformations that apply only to child layers and the most common use of a scene is to add an angle to the content of the visual effect.
The work is multiplied by the coordinate value by the number matrix to obtain a new coordinate representation of the original conversion version of the transformation. Because the core animation values can be specified in three dimensions, each coordinate point has four values that must be multiplied by a matrix of 14 rows and four columns. In the core animation, the transformation of the diagram by the catransform3d type Fortunately, you do not need to modify the structure of the field directly to the standard conversion. Core animations provide a comprehensive set of functions to create tables, translations, and comparisons of rotation matrices and matrices. In addition to manipulating transformations using features, the core animation extension key-value encoding support allows you to modify the transform using critical paths. A column can modify the critical path to see the catransform3d critical path.

Layer Tree

An application uses a core animation with three sets of layers of objects. Each group of objects in your app's content has different roles appearing on the screen:

    • The object model in the layer tree (or the simple "layer tree") is the most interactive that your application provides. Object Model objects in this tree store any animations of the target values. When you change the properties of a layer, you can use one of these objects.
    • The object in the representation tree contains any value in the flight that runs the animation. The layer tree object contains the target value of an animation, and the object representing the tree reflects the current value at the same time that it appears on the screen. You should never modify an object in this tree. Instead, you use these objects to read the values of the current animation, or create a new animation to begin with in these values.
    • Perform actual animations and private core animations in the object render tree in.

Each group of objects is organized into a hierarchy of views that you like in your application. In fact, for an application that makes all of its view layers, the initial structure of each tree matches the view hierarchy completely. However, an application can add additional layers of that layer of objects, layers with the needs of the view layer hierarchy. You may be in case that optimized content does not require the overhead of all views to do this for the performance of your application. Figure 1-9 shows the discovery layer breakdown in a simple iOS application. In the sample window, it contains a button and two separate layer objects. Each view has a corresponding layer object that forms part of the hierarchy.

The relationship between layers and views

Layer is not a view of your application, you cannot create a completely object-based visual interface. Provide an infrastructure layer for your point of view. Specifically, the layer makes it easier and more efficient to draw and animate the view of the content and maintain a high frame rate. However, there are many things that the layer does not do. Layers do not handle events, draw content, participate in response chains, or do many other things. Therefore, each application must also have one or more views to handle these types of interactions.
In iOS, each view is supported by a corresponding layer object, but in OS X, you have to decide what should be hierarchical however, you do not need to do this, you can also disable the layer in case of unnecessary and unnecessary overhead . Tiers increase application memory overhead but their interests tend to outweigh the disadvantages, so it's best to test your application's performance at the Disable layer.
When you make a view layer support, you create a view that is called layer support. In a layer of supported views, the system is responsible for creating the underlying objects and keeping that layer synchronized with the view. The support for all iOS view tiers is the same for most OS X. However, in OS X, you can also create a layer managed view which is a view that you provide layer objects. A layer of hosting, it needs to let go of the management layer's approach without modifying its response to change.

At last

The original "Core Animation Programming Guide".

Coreanimation Programming Guide (i) Core Animation basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.