-ios Training, iOS learning------- -type technology blog, look forward to communicating with you! ------------UIView and Calayer detailed
Research Core Animation has been a while, about core Animation, there is no good introduction to the Internet. Apple website has a special summary of the introduction, but it seems that the original rational things are not many, see people enveloping, feel, write that the person, in fact, is supposed to read people understand the interface animation technology principle. Today something else to use Linux, forget the SSH password, no way to re-set SSH, the results how can not remember how to set up SSH remote landing, no way to check the internet again, too wasted time, the pain of forgetting notes is how terrible things. In view of the core animation content is very complex, the application of the Obj-c language itself is also a lot of characteristics, so write a memo record, understand the people see if the error, but also feel free.
1.UIView is the basis for interface elements in iOS systems, and all interface elements inherit from it. It is entirely done by coreanimation (it does not seem to be the case on Mac). Its true drawing part is managed by a class called Calayer (Core animationlayer). UIView itself, more like a Calayer manager, accesses its properties related to drawing and coordinates, such as frame,bounds, and so on, essentially accessing the relevant properties of the Calayer it contains.
2.UIView has a layer property, you can return its primary Calayer instance, UIView has a Layerclass method that returns the class used by the primary layer, UIView subclasses, which can be overloaded by this method, To let UIView use a different calayer to display, for example, by
1
-(Class) Layerclass {
2
return ([Caeagllayerclass]);
3
}
Causes a UIView subclass to be drawn using GL.
3.UIView Calayer is similar to UIView's sub-view tree structure, or you can add a sub layer to its layer to complete some special representations. For example, the following code
1
Graycover = [[Calayer alloc] init];
2
Graycover.backgroundcolor = [[[Uicolor blackcolor]colorwithalphacomponent:0.2] cgcolor];
3
[Self.layer Addsublayer:graycover];
The target view is coated with a layer of black transparent film.
The 4.UIView layer tree is inside the system and is maintained by the system with three copies (this is a bit doubt).
The first, logical tree, is what you can manipulate in the code, such as changing the properties of a layer and so on.
Second, the animation tree, which is an intermediate layer, the system is changing the properties on this level for various rendering operations.
Third, show tree, the content of this tree is currently being displayed on the screen.
The logical structure of the three trees is the same, the difference is only the individual attributes.
5. How the Animation works
Outside of the main layer of uiview (I think so), the sublayer, that is, the properties of the sub-layer changes, the system will automatically animate, the animation duration has a default time, the personal feel about 0.5 seconds. During animation time, the system automatically determines which properties have changed, automatically animates the changed properties, generates an intermediate frame, and then continuously displays the animation effect.
6. Coordinate system (relationship to position and anchorpoint or stun)
Calayer coordinate system and uiview a bit different, it has a property called Anchorpoint, it uses the cgpoint structure, but the range is 0~1, that is, set according to the scale. This point is the coordinate origin of the various graphic transformations and changes the position of the layer's position, whose default value is {0.5,0.5}, which is the center of the layer.
A layer.anchorpoint = Cgpointmake (0.f, 0.F);
If this is set, the upper-left corner of the layer will be moved to the middle of the original position,
That's all I'm saying.
A layer.position = Cgpointmake (0.f, 0.F);
7. Analysis of real examples
This is the effect of ibook on the iphone, assuming that each page is a uiview, I think a page is affixed with two layers, the text layer to display the front of the content, the back layer with a text layer of the snapshot do affine flip, paste the text layer behind. Because the layer can set the display shadow, perhaps the shadow effect behind it is not displayed using a separate layer. As for the surface effect, I looked up a lot of data and had no results, presumably using a surface plot of GL?
8. The last one that's disgusting.
The layer can set a fillet display, such as a uibutton effect, or you can set a shadow display, but if a layer in the layer tree has rounded corners, the shadow effect for all layers in the tree will not be displayed. If you want to have rounded corners and want to shadow, as if only to do two overlapping uiview, a layer display rounded corners, a layer of the shadow ...
Calayer belongs to the core animation part of the content, more important but not very good understanding. Here is an excerpt from an article seen in the garden:
1.UIView is the basis for interface elements in iOS systems , and all interface elements are inherited from it. It is entirely by coreanimation to achieve it. The real drawing part of it is managed by a Calayer class . UIView itself is more like a Calayer manager, accessing its properties related to drawing and coordinates, such as Frame,bounds, is actually accessing the related properties of the Calayer it contains.
2. UIView has an important attribute layer that can return its primary calayer instance.
to access layers, read the Layer property of the UIView instance
Calayer *layer = Myview.layer
All objects inherited from UIView inherit this property. This means that you can convert, scale, rotate, and even add animations to other view classes such as navigation bars,tables,text boxes. Each uiview has a layer that controls how their content is ultimately displayed on the screen.
UIView the Layerclass method, you can return the class used by the main layer, UIView subclasses can overload this method to let UIView use a different calayer to display. code example:
-(Class) Layerclass {
Class]);
}
The code above enables a subclass of a uiview to be drawn using GL.
3. UIView's Calayer is similar to UIView's sub-view tree structure , or it can add a sub layer to its layer to complete some special representations. That is, the Calayer layer can be nested. Example code:
Graycover = [[Calayer alloc] init];
Graycover.backgroundcolor = [[Uicolor blackcolor] colorwithalphacomponent:0.2] cgcolor];
[Self.layer Addsublayer:graycover];
The above code will apply a layer of black transparent film to the target view.
4. The UIView layer tree is inside the system and is maintained with three copy. is the logical tree, here is the code can be manipulated, the animation tree, is an intermediate layer, the system on this level to change the properties, for various rendering operations, the display tree, the content is currently being displayed on the screen content.
5. The operation of the animation: changes to the UIView sublayer (non-primary layer) attribute, the system will automatically animate , the animation duration of the default value appears to be 0.5 seconds.
6. Coordinate system: Calayer coordinate system more than uiview a anchorpoint attribute, using the CGPOINT structure, the range is 0~1, is a proportional value. this point is the coordinate origin of the various graphic transformations and changes the position of the layer's position, whose default value is {0.5,0.5}, which is at the center of the layer.
A layer.anchorpoint = Cgpointmake (0.F,0.F);
If this is set, only the upper-left corner of the layer is moved to the original middle position, you must add this sentence:
A layer.position = Cgpointmake (0.F,0.F);
Finally: Layer can set the fillet display (Cornerradius), or you can set the Shadow (Shadowcolor). However, if a layer in the layer tree has rounded corners, the shadow effect on all layers of the tree is not displayed. So if you want to have rounded corners and shadows, the workaround can only do two overlapping uiview, one layer shows rounded corners, one layer shows shadows ...
7. Render : When updating the layer, the change cannot be displayed immediately on the screen. When all the layers are ready, you can call the Setneedsdisplay method to redraw the display.
[Gamelayer Setneedsdisplay];
To redraw part of the screen area, use the Setneedsdisplayinrect: method, which is updated by the zone in the CGRect structure:
[Gamelayer Setneedsdisplayinrect:cgrectmake (150.0,100.0,50.0,75.0)];
If the core graphics frame is used to perform rendering, the content of the core graphics can be rendered directly. Use Renderincontext: To do this thing.
[Gamelayer Renderincontext:uigraphicsgetcurrentcontext ()];
8. Transform: to add a 3D or affine transformation to a layer, you can set the transform or AffineTransform properties of the layer, respectively.
CharacterView.layer.transform = Catransform3dmakescale (-1.0,-1.0,1.0);
Cgaffinetransform transform = cgaffinetransformmakerotation (45.0);
BackgroundView.layer.affineTransform = transform;
9. Deformation: The rendering capability of the Quartz core enables two-dimensional images to be manipulated freely, as if they were three-dimensional. The image can be rotated, scaled and tilted at any angle in a three-dimensional coordinate system. Catransform3d's set of methods provides some magic-like transitions.
"Good Programmer's note sharing"--uiview and Calayer detailed