Learn iOS (3) UIView and its subclass with me (I)

Source: Internet
Author: User
Document directory
  • I. UIWindow

Before you start, I think you should read the story behind Mac OS X first, which is a very good article. Only by understanding what happened in the past can we have a deeper understanding of why it is now.

Sources of xib and nib

In Mac OS X 10.3, Project Builder was renamed as Xcode, which is now well-known. Before Xcode 3, Interface Builder used a binary file format named nib format. However, because nib cannot be read with the naked eye or managed using version management tools, Xcode 3 began to add a new text file format named xib, finally, the nib format is output in the project compilation phase. Unlike tools that generate static interface layout code, nib is not translated into the corresponding Objective-C code. During user program execution, the nib file is read and unwrapped, so the nib file is dynamically loaded at runtime.

Description of the UIView class

UIView inherits from the UIResponder class, so it mainly expresses two meanings

1. visualized (CALayer)
2. UIResponder)

Each UIView has an implicit Layer (implicit Layer), and the View itself is the Delegate of this implicit Layer.
Why is there a layer? Because the plotting and so on are completed on the layer and then merged. The UIView can be displayed only when a Layer is available.

Layer consists of two parts. Present layer and Model layer.
The present layer indicates the intermediate process status, while the Model layer indicates the start and end statuses.

Initialization Method

-(Id) initWithFrame :( CGRect) frame

The frame specifies the size and position of the View. The starting point is in the upper left corner.

 

 

Subclass of UIViewI. UIWindow

UIWindow is a container that contains all other views. Every program has a UIWindow. In the following code, we instantiate a UIWindow class after the program is started and call its makeKeyAndVisible method. This method makes the window visible on the screen.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];   self.window.backgroundColor = [UIColor whiteColor]; 
  [self.window makeKeyAndVisible];  return YES;}
 
Display View on screen

Once the window is visible on the screen, any view added to the window will be visible on the screen. In other words, to make a view visible on the screen, you need to add it to the window. When a view is added to the window, this view is called the subview of the window. Each view can have its own subview. Window is the root node in this hierarchy. As mentioned above, if a view is to be displayed on the screen, it must be used as the subview of the window. In addition to directly adding the subview of the window, the subview that has been added to the window is also indirectly used as the subview of the window, so it can also be displayed on the screen. You can refer to the structure (figure from iOS Programming 3rd). MKMapView is used as the subview of UIWindow, and UITextfield and UIButton are used as the subview of MKMapView. They are all displayed on the screen.

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.