Uiscreen and uiwindow and uiview for iOS development

Source: Internet
Author: User

Uiscreen (screen), uiwindow (window), and uiview (View) are several basic interface elements of IOS. Uiwindow and uiview are for iPhone applications.ProgramConstruct visual components of the user interface. Uiwindow provides a background platform for content display. uiview is responsible for describing most of the content and responding to user interaction.

 

1,Uiscreen

The uiscreen class represents the screen. According to tekuba's understanding, uiscreen is generally only used to obtain the screen size. For example:

Cgrect screenbounds = [[uiscreen mainscreen] bounds]; // The returned rect with the status bar (0.0, 0.0, 320.0, 480.0)

Cgrect viewbounds = [uiscreen mainscreen] applicationframe]; // rect (0.0, 20.0, 320.0, 480.0) that does not contain the status bar [iPhone Status Bar Height: 20 pixels]

 

2.Uiwindow

IPhone applications usually have only one window, indicating an instance of the uiwindow class. When the application is started (or loaded from the NIB file), create the window, add one or more views to the window, and display them. Then we seldom need to reference it again. The uiwindow object is the root of all uiviews, and the display of management and coordination applications. Generally, an application only has one uiwindow object. Even if multiple uiwindow objects exist, only one uiwindow can receive user touch screen events.

In iOS, The uiwindow object does not have a part such as a close box or title bar, which is common in Windows applications. Normal users cannot directly close it or perform other operations. All operations on the window must be implemented through its programming interface. Applications can use window objects to transfer events. The window object keeps track of the current first responder object and transmits the event when the uiapplication object initiates a request.

In Mac OS x, the parent class of nswindow is nsresponder, while in iPhone OS, the parent class of uiwindow is uiview. Therefore, the uiwindow is also a view object in IOS.

When creating an application window, you should always set its initial border size to the size of the entire screen. If your window is loaded from a NIB file, interface Builder cannot create a window smaller than the screen size. However, if your window is created programmatically, the expected border rectangle must be input during creation. Except for the screen rectangle, there is no reason to pass in other border rectangles. The screen rectangle can be obtained through the uiscreen object.CodeAs follows:

Self. Window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease];

Self. Window. rootviewcontroller = viewcontroller;

// Uiwindow has a Root View Controller-this view controller is used to configure the view that is first displayed when the form is displayed.

[Self. Window makekeyandvisible]; // This line of code displays the window containing the View Controller view on the screen.

 

3,View uiview

A view is an instance of the uiview class and defines a rectangular area on the screen. Views play a key role in displaying user interfaces and responding to user interface interactions. Each view object is responsible for rendering the content in the rectangular area of the view and responding to Operation events in the area. View is an important mechanism for interaction between applications and users.

In addition to displaying content and processing events, views can also be used to manage one or more child views. A subview is a view object embedded in the border of another view object. An embedded view is called a parent view or a superview. This layout method is called view hierarchy. A view can contain any number of subviews. By adding subviews to a subview, the view can be nested in any depth. The child view is always displayed above its parent view. Each parent view is responsible for managing its direct child views, adjusting their positions and sizes as needed, and responding to events they have not processed.

In iOS, the Visual View and View Controller work closely together. The view controller is used to handle view loading and unloading and interface rotation caused by device rotation, and interact with advanced navigation objects used to build complex user interfaces.

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.