Core Animation Basics

Source: Internet
Author: User
Tags image filter

Core Animation can be translated into Core animations, providing the foundation for graphic rendering and Animation. When using the core animation, you only need to set some parameters such as the start and end points. The remaining frame core animation is automatically completed for you. The core animation uses hardware acceleration without consuming cpu resources. In fact, the iOS apps we develop are intentionally or unintentionally using core animations. Animation does not replace View, but provides better performance together with View. Core Animation caches the content on the view to bitmap, so that bitmap can be operated directly on the graphic hardware. This improves the performance. Core animation location: 1. Layer Classes are the basis of core animation. Layer Classes provides an abstract concept that is familiar to developers who use NSview and UIview. The base layer is provided by the CAlayer class, And CAlayer is the parent class of all Core Animation layers. Like an instance of a view class, a CAlayer instance also has a separate superlayer and all the sublayers above. It creates a layered layer, we call it layer tree. Layers is drawn from the back and forward like views. During the painting, we need to specify the set shape relative to their superlayer and create a local coordinate system. Layers can perform more complex operations, such as rotate, skew, scale, and project the layer content ). The content of the layer is provided. (1) directly set the content attribute of the layer to a core graphics graph, or set it through delegation. (2) A proxy is provided to draw directly to the Core Graphics image context (the context of the Core image) (3) set the visual style attributes shared by any number of layers. For example, backgroundColor, opacity, and masking ). The max OS x application uses core image filters to achieve this visual attribute. (4) subclass CAlayer and complete any of the above technologies in more encapsulation methods. 1.1 ClassUsageCAEmitterLayerUsed to implement a Core Animation-based particle emitter system. the emitter layer object controls the generation of the participant and their origin. CAGradientLayerUsed to draw a color gradient that fills the shape of the layer (within the bounds of any rounded corners ). CAEAGLLayer/CAOpenGLLayerUsed to set up the backing store and context needed to dra W using OpenGL ES (iOS) or OpenGL (OS X ). CAReplicatorLayerUsed when you want to make copies of one or more sublayers automatically. the replicator makes the copies for you and uses the properties you specify to alter the appearance or attributes of the copies. CAScrollLayerUsed to manage a large scrollable area composed of multiple sublayers. CAShapeLayerUsed to draw a cubic bezr spline. shape lay Ers are advantageous for drawing path-based shapes because they always result in a crisp path, as opposed to a path you draw into a layer's backing store, which wocould not look as good when scaled. however, the crisp results do involve rendering the shape on the main thread and caching the results. CATextLayerUsed to render a plain or attributed string of text. CATiledLayerUsed to manage a large imag E that can be divided into smaller tiles and rendered individually with support for zooming in and out of the content. CATransformLayerUsed to render a true 3D layer hierarchy, rather than the flattened layer hierarchy implemented by other layer classes. QCCompositionLayerUsed to render a Quartz Composer composition. (OS X only) 1.2, anchorPoint, positionanchorPoint, also known as anchorPoint, has a great impact on animation. Describes the three example values based on the anchorPoint: 1.3. shows the relationship between the frame, bounds, position, and anchorPoint of the layer. In this example, the default value of anchorPoint is (0.5, 0.5 ), located at the center of the layer. The position value of a layer is (100.0, 100.0), and the bounds value is (0.0, 0.0, 120, 80.0 ). The calculated frame of the layer is (40.0, 60.0, 120.0, 80.0 ). If you create a new layer, only the frame of the layer is set to (40.0, 60.0, 120.0, 80.0), and the corresponding position attribute value is automatically set to (100.0, 100.0 ), and bounds is automatically set to (0.0, 0.0, 120.0, 80.0 ). Show that a layer has the same frame (such as), but in the figure, its anchorPoint attribute value is set to (0.0, 0.0), located in the lower left corner of the layer. The frame value of the layer is also (40.0, 60.0, 120.0, 80.0). The bounds value remains unchanged, but the position value of the layer has been changed to (40.0, 60.0 ). 2. For animation core animations, use basic animations and key frame animations to display layer content and selected Attribute animations. Animation classes of all core animations are inherited from the CAAnimation class. CAAnimation implements the CAMediaTiming protocol and provides animation duration, speed, and repeated counting. CAAnimation also implements the CAAction protocol. This Protocol provides a standardized response for layers to trigger an animation action. The animation class also defines a time function that uses the besell curve to describe the animation changes. For example, a linear timing function keeps the speed unchanged throughout the animation lifecycle, while a gradient-out timing function) the animation slows down when it approaches its lifecycle. The core animation provides a series of abstract and refined animation classes. For example, CATransition provides a transition effect for layer changes, which can affect the entire content of the layer. Fade, push, and reveal layers during the animation. These transition effects can be extended to your custom Core Image filter. CAAnimationGroup allows a series of animation effects to be combined to display animations in parallel. 2.1 animation class CAPropertyAnimation: it is an abstract subclass. It supports the attributes specified in the Key Path of the animation display layer. Instead, it uses its subclass CABasicAnimation and CAKeyframeAnimation. modify attributes in its subclass to run the animation. CABasicAnimation: simple modification for layer attributes. This animation class is executed by default when attributes of many layers are modified. For example, CAKeyframeAnimation: supports key frame animation. You can specify the Key Path animation of the layer attribute, including the value of each stage of the animation, and a series of values of the Key Frame Time and timing functions. During animation running, each value is replaced by a specific insert value. Core animations and Cocoa Animation use these Animation classes at the same time. 2.2 how to use multiple animation effects to overlay the position, alpha, frame, and other attributes during the animation execution? CAAnimationGroup can combine the three animations for execution: [cpp] CAAnimationGroup * animGroup = [CAAnimationGroup animation]; animGroup. animations = [NSArray arrayWithObjects: moveAnim, scaleAnim, opacityAnim, nil]; animGroup. duration = 1; [view. layer addAnimation: animGroup forKey: nil]; 2.3 Each modification to the animation attribute of the transaction management layer must be a part of the transaction. CATransaction is the core animation that coordinates multiple animation atomic update and display operations. Transactions support nesting. 2.4 inheritance relationship diagram of Core Animation class

Related Article

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.