The difference between UIView and Calayer

Source: Internet
Author: User

1. UIView is the basis for interface elements in an iOS system , and all interface elements are inherited from it. It is entirely by coreanimation to achieve it. its true drawing part 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 the layer, read the UIView instance's Layer property Calayer *layer = Myview.layer

Class) Layerclass { return ([Caeagllayer class]);}

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];    

6. Coordinate system: The coordinate system of Calayer is more than uiview a anchorpoint attribute, denoted by the cgpoint structure, The range is 0~1, which 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 will be moved to the original middle position, you must add this sentence:
a layer.position = Cgpointmake (0.F,0.F);

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];

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.

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.

The difference between UIView and Calayer

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.