iOS development diary 12-calayer and UIView

Source: Internet
Author: User
Tags uikit

Today Bo Master has a content to draw the demand, encountered some difficulties, here and we share, hope to progress together.

Today share with you the difference between Calayer and UIView:

1.UIKit uses Uiresponder as the response object to respond to and process events passed by the system. UIApplication, Uiviewcontroller, UIView, and all Uikit classes derived from UIView, including UIWindow, inherit from the Uiresponder class directly or indirectly.

The interface that handles various events and event passing is defined in Uiresponder, and Calayer directly inherits NSObject, and there is no corresponding interface for handling events, the most obvious difference being that view can accept and handle events, and Layer can not

2. A frame of a layer is determined by its anchorpoint,position,bounds, and transform, and a view frame is simply a frame that returns to the layer, the same view as the cent Er and bounds are also some properties that return Layer.

When the view is displayed, the Calayerdelegate,view of the UIView as a Layer is drawn by the internal Calayer

3. Inside each UIView is a calayer that provides the drawing and display of the content behind it, and the UIView dimension style is provided by the inner Layer. Both have a tree-like hierarchy, and inside the layer there is a subviews inside the sublayers,view. But the layer is a anchorpoint more than the View.

The layer is maintained within the three-point layer tree, which is the Presentlayer tree (the Modelayer tree), the render tree, and in the animation of iOS, we modify the properties of the animation, which is actually The Presentlayer property value of the Layer, and the final display on the interface is actually the Modellayer that provides the view

4.CALayer is the default modification property to support implicit animation, when animating the layer of UIView, the View as the layer of the proxy, layer through Actionforlayer:forkey: to the View request the corresponding action (animation behavior ), for each UIView there is a layer, which is called the Rootlayer, rather than the root layer of the View, which is referred to as non-rootlayer. Our property modification to UIView does not produce the default animation at all times, and the default animation time default value is 0.25s when the individual layer property is modified directly.

5. Share with you a little bit of uiview conversion uiimage.

+ (uiimage*) Imagewithuiview: (uiview*) view{     uigraphicsbeginimagecontext (view.bounds.size);  Cgcontextref Currnetcontext = Uigraphicsgetcurrentcontext (); [View.layer Renderincontext:currnetcontext]; uiimage* image = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); return image;     

iOS development diary 12-calayer and UIView

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.