Uiapplication,uiwindow,uiviewcontroller,uiview (layer) Brief introduction

Source: Internet
Author: User

One: uiapplication: Single case (more on the article in the following example, as you can now know, the Singleton has only one object throughout the application's life cycle).

App start-up process

After opening the program-"

    • 1:main function

    • 2:uiapplicationmain function

    • 3: Initialize UIApplication (Create)

    • 4: Set the uiapplication agent and corresponding agent properties

    • 5: Turn on event loop, listen for system events

    • 6 Monitoring info. plist file to see if there are main.storyboard files present

There:/***************************************** Gorgeous split line ******************************************/

    • 1: Load Main.storyboard

    • 2: Create a UIWindow on top of storyboard,

    • 3: Set window's root controller

    • 4: Traverse all child controls above the controller without creating the corresponding control

No:/***************************************** Gorgeous split-line ******************************************/

    • 1: Create UIWindow with a strong reference
    • Self.window = [[UIWindow alloc] init];

    • 2: Set window's frame as the bounds of the screen
    • Self.window.frame = [UIScreen mainscreen].bounds;

    • 3: Set window's root controller
    • Self.window.rootViewController = [[Uiviewcontroller alloc] init];

    • 4: Windows as main window and display to interface
    • [Self.window makekeyandvisible];

Here is a very important but very few people to pay attention to the place, also as an iOS programmer must know, that is the main function, we know that the main function is a program's entry, then in the iOS development of the main function has what to note:

    • int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname);

ARGC, argv: direct transfer to Uiapplicationmain for related processing can be

Principalclassname: Specifies the application class name (symbol of the app), which must be uiapplication (or subclass). If nil, use the UIApplication class as the default value

Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol

Method:

 1//When app launch is complete call 2 3-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) LA  Unchoptions {4 5 6 7 NSLog (@ "%s", __func__), 8 9 return yes;12}14//app is about to lose focus when calling 18 (void) Applicationwillresignactive: (uiapplication *) application {NSLog (@ "%s", __func__); 22 23}24 25 26 27     App enters backstage-(void) Applicationdidenterbackground: (uiapplication *) application {NSLog (@ "%s", __func__); 32 33 Save some data.}38 (void) Applicationwillenterforeground: (UIApplication *) A When the app is about to enter the foreground pplication {NSLog (@ "%s", __func__),}48//app is about to get focus 52 53//When the application gets the focus, it can interact with the user.-(void) Applicationdidbecomeactive: (uiapplication *) application {NSLog (@ "%s", __func__), and the application is closed when the app is shut down -(void) Applicationwillterminate: (uiapplication *) application {66 67 68 69}70 71 72 73//Monitor Memory warning-(void) ApplicationdidreceivememoRywarning: (uiapplication *) application76 NSLog (@ "Memory Warning"); 80 81//Clear Picture Cache 82 83}84 85   

UIApplication common functions for Singleton objects:

Get the symbol of the app

UIApplication *app = [UIApplication sharedapplication];

Application Picture Reminder Number: (registration is required here)

1     app.applicationiconbadgenumber = 2  3      4  5     //Create notification object 6  7     Uiusernotificationsettings *settings = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge Categories:nil]; 8  9     //Registered user Notice     [app registerusernotificationsettings:settings];

Networking status 1 app.networkactivityindicatorvisible = YES;

Set the status bar

1 App.statusbarhidden = NO; 2 3 App.statusbarstyle = uistatusbarstylelightcontent;

-(BOOL) OpenURL: (nsurl*) URL;

OpenURL: Some of the functions of the method are

1     Call 2  3     uiapplication *app = [UIApplication sharedapplication]; 4  5     [app Openurl:[nsurl urlwithstring:@ "tel://10086"]; 6  7      8  9     SMS     [app Openurl:[nsurl urlwithstring:@ "sms://10086"]];12) e-     Mail 16     [App Openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"]];18     Open a Web resource     [ App Openurl:[nsurl urlwithstring:@ "http://ios.itcast.cn"]];24 25  

Two: UIWindow

UIWindow is a special kind of uiview that usually has at least one UIWindow in an app.

After the iOS program starts, the first view control created is UIWindow, then the controller's view is created, the controller's view is added to the UIWindow, and the controller's view is displayed on the screen.

An iOS program can be displayed on the screen entirely because it has UIWindow

It says that without UIWindow, you can't see any UI interface.

There are two common ways of adding UIView to UIWindow:

    • -(void) Addsubview: (UIView *) view;

The view is added directly to the UIWindow, but the view corresponding Uiviewcontroller is not ignored

    • @property (Nonatomic,retain) Uiviewcontroller *rootviewcontroller;

Automatically add Rootviewcontroller view to UIWindow, responsible for managing the Rootviewcontroller lifecycle

Common methods

    • -(void) Makekeywindow;

Make current UIWindow into Keywindow (main window)

    • -(void) makekeyandvisible;

Make the current UIWindow into Keywindow and show it

[UIApplication sharedapplication].windows

A list of UIWindow that opens in this app so you can touch any of the UIView objects in your app

(usually input text pop-up keyboard, in a new UIWindow)

[UIApplication Sharedapplication].keywindow

The UIWindow used to receive message events for keyboards and non-touch classes, and only one uiwindow per time in a program is Keywindow. If a text box inside a UIWindow cannot enter text, it may be because this uiwindow is not Keywindow

View.window

Get the UIWindow where a uiview is located

UIWindow also has a property to note, although I usually seldom use:

    • @property (nonatomic) Uiwindowlevel windowlevel;

Corresponds to the De property value:

    1. Uikit_extern Const Uiwindowlevel Uiwindowlevelnormal;
    2. Uikit_extern Const Uiwindowlevel Uiwindowlevelalert;
    3. Uikit_extern Const Uiwindowlevel Uiwindowlevelstatusbar;

Three: Uiviewcontroller

Creation of the Controller

• Understand the Uistoryboard object, through which you can load the storyboard file Note: There must be storyboard, the creation of Uistoryboard objects makes sense, Alloc init creates uistoryboard objects without meaning
1.1> Instantiateinitialviewcontroller: The controller that the default load arrow points to

1.2> Instantiateviewcontrollerwithidentifier: Locates the controller in storyboard according to the identity and creates.

0 logo can not be storyboard, will be error, you must have this logo to do.

Create a view (empty project) of the controller via Xib • First, you have to have xib.

1 xib Note: (Demo no consequences)
1> Xib must have a view describing the controller's view, because the controller's view property must have a value.
2> xib need to specify which controller to describe, description UIView not need, because xib can describe a lot of uiview, not fixed dead, but the controller is not the same, a xib is used to describe a controller.
Xib There may be many view, need to drag line to indicate which is the controller's view

2 Xib and Storyboard difference Storyboard has specified the controller's view, do not need our tube, xib need us to manage manually.

Uiviewcontroller startup process

System default Practice: If storyboard or xib are specified, the view of the controller they describe is loaded

1-(void) Loadview 2  3 {4  5     6  7} 8  9  Ten-(UIView *) view12 (     _view = nil) {1 6         [self loadview];18] [self         viewdidload];20     }22     return _view;24 25}

Anyway Loadview is called when we customize the view, Apple provides this method is the purpose of this, so we later customize the view when not implemented in Viewdidload, because viewdidload means that the view is loaded after the call, So this time there is a view, we can create a view, although yes, but this is not a waste of memory.

1     //1. Create Windows 2  3     self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; 4  5      6  7     //Set the color of the window 8  9     self.window.backgroundColor = [Uicolor purplecolor];10     //2. Create the root controller in the settings window of the root controller     uiviewcontroller *VC = [[Uiviewcontroller alloc] init];16 +/     /Set the root controller of the window, The bottom layer automatically adds the view of the root controller to the window and lets the controller view have a rotation function of     Self.window.rootViewController = vc;22     //3. Display window     makekeyandvisible//: Let the window become the main window of the application and display the window     [Self.window makekeyandvisible];30     32 33     return yes;34 35  

Life cycle:

Four: UIView (Layer)

Creation of the view of the controller

1> Loadview effect: Typically used to create a custom view

2> Loadview When to call: When the controller's view is not created, it calls Loadview to create a view of the controller.

3> Loadview Use Note: If you rewrite Loadview without creating a view of the controller, you cannot use Self.view, which can cause a dead loop.

Attention:

Rewrite Loadview, not will not load xib, the controller's view is determined by Loadview, Loadview show what color, is what color.
Loadview simply creates the controller view and does not determine the color of the controller's view.
Understand Loadview call moment: The first call to Self.view, the underlying will call Loadview method, create the controller's view, this time the view is the color of Loadview, but

Vc.view.backgroundColor, is to get the controller's view and set a color, the Loadview set the color to cover.
In Viewdidload also set the color, or Vc.view.backgroundColor decided, because

Vc.view View, view

Loadview simply creates the controller view and does not determine the color of the controller's view.

Vc.view.backgroundColor, is to get the controller's view and set a color, the Loadview set the color to cover.
In Viewdidload also set the color, or vc.view.backgroundColor decision, because Vc.view is to get the controller's view, only the controller's view load is complete, to get to, so first call viewdidload.

Understand Loadview call moment: The first call to Self.view, the underlying will call Loadview method, create the controller's view, this time the view is the color of Loadview, but

There is also a concept worth noting, that is the layer of a layer of things, what is his use? What's his relationship with drinking uiview?

A detailed explanation of the properties and methods in UIView:

    • @interface uiview:uiresponder<nscoding, Uiappearance, Uiappearancecontainer, uidynamicitem>

  1/** 2 3 * Initializes a UI control with a Frame 4 5 */6 7-(ID) initWithFrame: (CGRect) frame;  8 9//YES: Ability to interact with users @property (nonatomic,getter=isuserinteractionenabled) BOOL userinteractionenabled;                                 Default is YES 14 15 16 17//A tag for the control (the parent control can find the corresponding child control via tag) @property (nonatomic)                Nsinteger tag;   Default is 0 20 21 22 23//layer (can be used to set fillet effect \ Shadow effect) @property (Nonatomic,readonly,retain) Calayer *layer; @end @interface UIView (uiviewgeometry) 34 35//position and size (in the upper left corner of the parent control is the origin of the coordinates (0, 0)) Notoginseng @proper Ty (nonatomic) cgrect frame; 38 39 40 41//position and size (in its own upper left corner is the coordinates origin (0, 0)) @property (nonatomic) cgrect bounds;       44 45 46 47//Midpoint (in the upper-left corner of the parent control is the coordinate origin (0, 0)) @property (nonatomic) Cgpoint Center;   50 51 52 53//deformation properties (pan \ Zoom \ Rotation) @property (nonatomic) Cgaffinetransform transform; Default is Cgaffinetransformidentity 56  */YES: Support multi-touch @property (nonatomic,getter=ismultipletouchenabled) BOOL multipletouchenabled; Default is NO @end @interface UIView (uiviewhierarchy) 68 69//Parent control @property (nonatomic,r eadonly) UIView *superview; 72 73 74 75//child control (the newly added control is defaulted to the Subviews array, and the newly added control is displayed by default on top \ Topmost) @property (nonatomic,readonly,copy) Nsarray *su Bviews; 78 79 80 81//Get the window of the current control @property (nonatomic,readonly) UIWindow *window; 84 85 86 87//Remove a control from the parent control--(void) Removefromsuperview; 90 91 92 93//Add a child control (you can insert a child control into the Subviews array index this position) 94-(void) Insertsubview: (UIView *) View Atindex: (Nsinteger) I Ndex; 96 97 98 99//Exchange Subviews The position of the child controls in the array 101-(void) Exchangesubviewatindex: (Nsinteger) index1 Withsubviewatindex: (nsin Teger) index2;102 103 104 105//Add a child control (the newly added control is defaulted to the Subviews array, and the newly added control is displayed by default on top \ Topmost) 106 107-(void) Addsubview: (UIView *) view;108 109 110 111//Add a child control view (blocked under Siblingsubview) 112 113 -(void) Insertsubview: (UIView *) View Belowsubview: (UIView *) siblingsubview;114 115 116 117//Add a child control view (covered in SIBLINGSUBV Iew) 118 119-(void) Insertsubview: (UIView *) View Abovesubview: (UIView *) siblingsubview;120 121 122 123//pull a child control to the top ( Top) to show 124-(void) Bringsubviewtofront: (UIView *) view;126 127 128 129//Drag a child control to the bottom (the bottommost) to show the "131"-(void) Sendsubvi Ewtoback: (UIView *) view;132 133 134 135/** System automatic call (left to subclass to implement) **/136 137-(void) Didaddsubview: (UIView *) subview;138 139-(V OID) Willremovesubview: (UIView *) subview;140 141 142 143-(void) Willmovetosuperview: (UIView *) newsuperview;144 145-(VO ID) didmovetosuperview;146 147-(void) Willmovetowindow: (UIWindow *) newwindow;148 149-(void) didmovetowindow;150 151/*  * System automatically calls **/152 153 154 155//Is not a child control of a view or child control (whether a descendant of a view) 156 157-(BOOL) Isdescendantofview: (UIView *) view;     Returns YES for self.158 159 160 161//The corresponding child control (or child control of child controls) is obtained by Tag 162 163-(UIView *) Viewwithtag: (nsinteger) tag; Recursive search. Includes SELF164 165 166 167/** System Auto-call (leave subclass to implement) **/168 169//control frame changes when it is called, General here Rewrite Layout child control position and size 170 171//Rewrite This write method, must call [Super Layou tsubviews];172 173-(void) layoutsubviews;174 175 176 177 @end178 179-181 @interface UIView (uiviewrendering) 182 183 YES: Content beyond the border of the control is cut off 184 185 @property (nonatomic) BOOL clipstobounds;186 187 188 189//Background Color 191 @property (nonatomic,copy) Uicolor *backgroundcolor;                      Default is nil192 193 194 195//Transparency (0.0~1.0) 196 197 @property (nonatomic) cgfloat Alpha;              Default is 1.0198 199 201//YES: Opaque No: Transparent 202 203 @property (nonatomic,getter=isopaque) BOOL                     Opaque Default is YES204 205 206 207//YES: Hide NO: Show 208 209 @property (Nonatomic,getter=ishidden) BOOL Hidde                N;210 211 212 213//Content Mode 214 215 @property (nonatomic) Uiviewcontentmode Contentmode; Default is UiviewcontentmodesCALETOFILL216 217 @end218 219 220 221   

/******************************************************************************

*                                                                            *

* UIView Classification-block Animation method *

*                                                                            *

* Icocos--description *

*                                                                            *

******************************************************************************/

1 @interface UIView (uiviewanimationwithblocks) 2  3 + (void) Animatewithduration: (nstimeinterval) duration delay: ( Nstimeinterval) Delay options: (uiviewanimationoptions) options animations: (void (^) (void)) Animations completion: ( void (^) (BOOL finished)) completion; 4  5 + (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) completion; 6  7   8  9 + (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations;10 One + (void) Animatewithduration: (nstimeinterval) Duration delay: (nstimeinterval) delay usingspringwithdamping: ( CGFloat) Dampingratio initialspringvelocity: (cgfloat) Velocity options: (uiviewanimationoptions) Options animations: ( void (^) (void)) animations completion: (void (^) (BOOL finished)) completion;12 @end14  16 17  

V: Uiapplication,uiwindow,uiviewcontroller,uiview (layer)

Uiapplication,uiwindow,uiviewcontroller,uiview (layer) Brief introduction

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.