Go UIView and Calayer.

Source: Internet
Author: User

(1) Lao zu

All things in the root, UIView and Calayer are all old fathers are nsobjet.

The inheritance structure of 1:uiview is: Uiresponder:nsobject.

Can see UIView's direct parent class is Uiresponder class, Uiresponder is GSM?

The official explanation:

The Uiresponder class defines a interface for objects, respond to and handle events. It is the superclass of UIApplication, UIView and its subclasses (which include UIWindow). Instances of these classes is sometimes referred to as responder objects or, simply, responders.

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in this area. At runtime, a-view object handles the rendering of any content in it area and also handles any interactions with that con Tent. The UIView class itself provides basic behavior for filling it rectangular area with a background color. More sophisticated content can is presented by subclassing UIView and implementing the necessary drawing and Event-handlin G Code yourself. The UIKit framework also includes a set of standard subclasses. range from simple buttons to complex tables and can is Used As-is. For example, a uilabelobject draws a text string and a Uiimageview object draws an image.

Visible Uiresponder is used to respond to events, that is, UIView can respond to user events.

The inheritance structure of 2:calayer is: NSObject.

Inherited directly from NSObject, because the Uiresponder class is missing, so Calayer cannot respond to any user events.

The Calayer class is the model class for Layer-tree objects. It encapsulates the position, size, and transform of a layer, which defines its coordinate system. It also encapsulates the duration and pacing of a layer and its animations by adopting the Camediatiming protocol, which D Efines a layer ' s time space.

As can be seen from the official explanation, Calayer defines basic attributes such as position, size, transform, animations, and so on. Where did the UIView size, frame, and position come from? The official explanation above does not explain this, and we'll analyze it later.

So far we have learned the basic information of UIView and Calayer and the main responsibility for dealing with things.

(2) Affiliation framework

1:uiview is defined in the/system/library/frameworks/uikit.framework.

And what does this do?

The UIKit framework provides the classes needed to construct and manage a application ' s user interface for IOS. IT provides an Application object, event handling, drawing model, Windows, views, and controls specifically designed for a Touch screen interface.

Visible Uikit is mainly used to build the user interface, and can respond to events (complacent and UIView of the parent class Uiresponder, as for the Uiresponderd implementation principle is not the purpose of this analysis, do not do too much explanation)

Think of a problem here uiview, since it is a user interface, how did he draw the information such as pictures and text?

2D image rendering in iOS is implemented through Quartzcore.framework. Is it achieved through quartzcore.framework? How does that relate to quartzcore.framework?? We'll see it later.

2:calayer is defined in the/system/library/frameworks/quartzcore.framework. and Calayer as a low-level, underlying object that can host the drawing content appears in the frame.

Now compare UIView and calayer to display information such as picture text. Does Apple offer two sets of drawing mechanisms? No.

UIView the biggest difference compared to Calayer is that UIView can respond to user events, and Calayer is not. UIView focuses on the management of display content, and Calayer focuses on drawing content.

As we all know, Quartzcore is the base library for image rendering in iOS. and Calayer is defined in the framework. is UIView the bottom realization is Calayer??

The official made a clear explanation:

Displaying Layers in views

Core Animation doesn ' t provide a means for actually displaying layers in a window, they must is hosted by a view. When paired with a view, the view must provide event-handling for the underlying layers, while the layers provide display of the content.

The view system in IOS are built directly on top of Core Animation layers.  Every instance of UIView automatically creates an instance of a Calayer class and sets it as the value of the view ' s layer Property. You can add sublayers to the view ' s layer as needed.

On Mac OS X You must configure an NSView instance in such a to the It can host a layer.

This shows that UIView is a high-level package based on Calayer. The view system in IOS are built directly on top of Core Animation layers.

Methods of UIView:

Layerclass-implement This method only if you want your view to use a different Core Animation layer for its backing stor E. For example, if is using OpenGL ES to does your drawing, you would want to override this method and return the CAEAG Llayer class.

The method retains the essence of uiview. That is, any display of the content managed by UIView is also affected by Calayer.

    1. (3) Similar support

1: Similar tree-shaped structure

2: Show how content is plotted

3: Layout constraints

    1. (4) What UIView is and what to do

UIView is used to display content and can handle user events

    1. (5) What Calayer is and what to do

Calayer is used to draw content, to animate the content dependent on the UIView to be displayed, and not to handle user events.

    1. (6) Why there are two sets of structures

Not two sets of systems, UIView and calayer are interdependent relationships. UIView relies on content provided with Calayer, Calayer relies on the container provided by Uivew to display the content being drawn. In the final analysis Calayer is the basis of all this, if no calayer,uiview itself will not exist, UIView is a special calayer implementation, adding the ability to respond to events.

    1. (7) The relationship between the two

Hair to the skin, blood to the flesh, spirit to the soul, the man's relationship to the kidney. Relationship of Dependence

Conclusion:

UIView from Calayer, above Calayer, is calayer high-level implementation and encapsulation. All features of the UIView are derived from Calayer support.

Go UIView and Calayer.

Related Article

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.