IOS Core Animation Animation Primer Learning (I.) basics
reference:https://developer.apple.com/library/ios/documentation/cocoa/conceptual/coreanimation_guide/ introduction/introduction.html#//apple_ref/doc/uid/tp40004514
In iOS, a layer is automatically configured in each view, and we can't create a new one, and in Mac OS, view defaults to no layer. You need to manually set whether the layer is turned on (the default is on after 10.8), because it takes a cost to open the layer, which is the overhead of additional memory.
View is responsible for displaying the content, and the layer is responsible for displaying the geometry of the content, the position on the screen, whether it is rotated, scaled, transparency, and so on.
Like view, layer also has frame and bounds two properties, but we can not artificially change the value of frame, frame is determined by position and bounds two properties. Bounds well understood, a wide and a high, decided their own size. Position is the seat coordinate relative to the parent view. It is important to note that exactly which point is relative to the parent view's coordinates? Here we need to first understand the concept of a property: Anchorpoint (Anchor Point). It is a unit vector, and X, Y is a float value of [0.0,1.0] that represents the position relative to its own width, and the default value is (0.5,0.5), which is the center point of the layer.
Looking at an example, we can easily understand the relationship of Position,bounds,anchorpoint. (iOS's coordinate system is the origin point on the left, OS X is the origin of the bottom left, which is mainly said iOS)
What is the use of anchorpoint? At rest we really do not see, anchorpoint different to the whole layer has any effect, we look at another picture:
Haha, as the name implies, Anchor Point is the meaning of fixed point, if the execution of rotation, it is around the anchor point to chant. Of course, if the position is moved, it is equivalent to pulling the anchor point in motion.
Position and Anchorpoint are actually a point, but position is a dot, and Anchorpoint is a vector. So position+anchorpoint+bounds can determine a layer.
Want to learn animation, light on the plane moving to move, wandering also do not mean Ah, layer also support 3D animation (in fact, personal feeling should be called pseudo-dimensional, haha).
Here we first want to understand a property, transform (change matrix). Each layer has two transform,transform&sublayertransform. Transform also works with layer and its sublayer to perform animations such as zooming, rotating, moving, and so on. Sublayertransform, as the name implies, is only for sublayer changes and is often used to add perspective to its presentation.
Tranform is actually a 4x4 matrix,
Math good students should see what the meaning, but fortunately we do not have to directly manipulate the matrix, with the setting of key-value pairs can be completed several of the matrix changes, refer to Catransform3d key Paths.
Take a look at the demo below and we'll get a sense of what each value in the matrix means.
Identity is the unit matrix by default, without any changes.
The translate is a translational matrix that changes after [X+tx, Y+ty, Z+tz, 1].
Scale is the scaling matrix, which changes after [X.tx, Y.ty, Z.tz, 1].
The following three distributions are in x-axis, y-axis, z-axis, rotation angle θ, with x-axis rotation as an example, after the change for [X, y.cosθ+z.sinθ,-y.sinθ+z.cosθ, 1].
It might be a bit dizzy at first, but it doesn't matter, the iOS system gives us a function that specifically performs these common changes, referencing animation functions Reference.
Layers, like view, are organized in a tree structure, and the Core animation app uses 3 sets of layer objects to control what is displayed dynamically on the screen.
The model layer tree, called layer tree, is the pattern of the layer we are impressed with, which stores the change information, which is useful when you modify the properties of a layer.
Presentation trees: A dynamic tree used to store the value of a layer on the screen at some point in time of the animation, cannot modify its value, can use its value to determine whether to open a new animation, or to determine the collision and so on.
Render tree: Render trees that provide true animations and are not modifiable for core animation.
Each layer object has a tree structure that exactly matches the view's tree structure, and each view has a layer object corresponding to it. But a little bit like the view tree, where you can add extra layer objects to a layer's tree structure, we can add extra layer objects to optimize the view's dynamic effect without affecting the view overhead.
Note: The presentation tree can only be read during animation execution, unlike the layer tree, which always responds to the final state of the layer animation when it is read.
This summary is mainly to the layer of understanding, we are frame,bounds,position,anchorpoint,transform and other properties, and layer of the three tree-shaped structure have a deeper understanding of it? Beginners learn to progress together, and welcome the masters to criticize and correct them.