Core Animation
**core animation** is the base engine for graphics rendering and animation in iOS and OS X systems, and can be used to animate the app's view and other visible elements. When animating with **core animation**, **core animation** will help you draw every frame you need for the animation, and all you have to do is specify several animation parameters (such as the start and end positions) and the notification **core animation** to start. At this point **core animation** will be rendered quickly using the appropriate graphics hardware. This automatic graphics accelerated rendering produces high frame rates and smooth animations without increasing CPU load and slowing down the app's running speed.
In fact, **core animation** not only can be used to do animation, animation is only the tip of its role. **core Animation * * is a composite engine. Its job is to combine the different visual content on the screen as quickly as possible, and the content is decomposed into separate layers stored in a system called a layer tree.
Base of layer Core Animation
------------------------------------
in iOS, all views derive from a base class called UIView. UIView can handle touch events and can support core graphics based drawings that can do affine transformations (such as rotation or zooming), or simple animations like sliding or gradient.
layer layers are similar to UIView. are also some rectangular blocks that are managed by hierarchical relationships. It can also contain some content, manage sublayers, animate and change. However, the layer object cannot be processed with user interaction, which is also the biggest difference from UIView.
Each view has its own layer object. That is backing layer. The layer captures the contents of the view in a single bitmap to use the hardware for the appropriate operation. Layers are often used as a way to manage the corresponding view content (you can, of course, create separate layer objects as needed). The view's responsibility is to create and manage this layer to ensure that the corresponding layer is doing the same thing in the corresponding hierarchy when the view is added or removed in the hierarchy relationship.
Actually the layers behind these are really used to display and animate on the screen, and UIView is just one package for it, providing some of the specific features of iOS that are similar to touch, as well as the advanced interface of the core animation approach.
But why is iOS providing two parallel hierarchies based on UIView and Calayer? Why not use a simple hierarchy to handle everything? This is due to separation of duties, which avoids a lot of duplication of code. On iOS and Mac OS two platforms, there are many differences between event and user interaction, multi-touch based user interface and mouse-based keyboard are essential differences, which is why iOS has Uikit and UIView, but Mac OS has AppKit and nsview reasons. They are functionally similar, but there are significant differences in implementation. We can use a small range of MV mode to understand. Layer is a DataObject, when the view occurs when the property data changes will notify the layer to do the corresponding changes and display, and only deal with the user's interaction.
views can respond to event layers, but in terms of content processing, layers have more features that view does not have.
1. Border (borer), fillet (Corner), Shadow (shadow)
2.3D Transform
3. Non-rectangular area
4. Transparent masking
5. Multi-stage nonlinear animation.
These will be explained slowly.
Geometry properties for views and layers
----------------------------
When we change some of the properties of the layer, we change only some of the state information of the layer. When a change triggers the animation, the layer will give its buffered bitmap and state information to the graphics hardware to render the new bitmap with the new state information. The graphics hardware renders much faster than the rendering speed of the software. Show the process of drawing
Because layer changes a static bitmap, it differs greatly from the traditional rendering technique. When a view-based change occurs, the view's drawrect is called: The method is redrawn with the new parameters. But this drawing is made on the main thread and consumes the CPU.
Layer some properties that can be changed:
Simple mutable properties: Frame, Bounds,center,position
--------------------------------------------------------
UIView *view = [[UIView alloc] Initwithframe:cgrectmake (10, 10, 40, 50)];
View.backgroundcolor = [Uicolor Redcolor];
Calayer *layer = View.layer;
[Self.view Addsubview:view];
NSLog (@ "View ' s frame =%@, view's bound =%@ View ' s center =%@", Nsstringfromcgrect (View.frame), Nsstringfromcgrect (view.b Ounds), Nsstringfromcgpoint (View.center));
NSLog (@ "Layer ' s frame =%@, layer ' s bound =%@, layer ' s position =%@", Nsstringfromcgrect (layer.frame), Nsstringfromcgrect (Layer.bounds), Nsstringfromcgpoint (layer.position));
Result: View ' s frame = {{Ten, Ten}, {+, 0}, view ' s bound = {{, 0}, {+, +}} View ' center = {30, 35}
Layer ' s frame = {{Ten, Ten}, {+, +}}, layer ' s bound = {{0, 0}, {30, +}}, layer ' s position = {35}
From the above results we can see that the view and layer objects have a frame, followed by the bound property. Frame is relative to the parent view/layer, and is a relative relationship. The upper-left corner is the (0,0) point. A Bound is a property relative to itself. Represents its own geometry.
Center is the central coordinate of the view relative to the parent view.
Positon is the center coordinate of the layer relative to the parent layer
Core Animation (i)