IOS-create UIWindow, and ios create uiwindow
After the iOS program is started, the first attempt to create the control is UIWindow. Then, create the view of the controller and add the view of the Controller to the UIWindow.
APPdelegate. m
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Override point for customization after application launch. // window Notes: 1. do not be destroyed. Make a strong reference. 2. required window size // 1. create window object self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. window. backgroundColor = [UIColor yellowColor]; // 2. create the root controller of the window and assign the value UIViewController * rootVc = [[UIViewController alloc] init]; rootVc. view. backgroundColor = [UIColor greenColor]; self. window. rootViewController = rootVc; // 3. display window [self. window makeKeyAndVisible]; return YES ;}
Both the keyboard and status bar are windows.
UITextField *text = [[UITextField alloc] init];[text becomeFirstResponder];[self.window addSubview:text];
Window Level UIWindowLevelNormalUIWindowLevelStatusBarUIWindowLevelAlert
Alert is the largest. You can add or subtract layers.
Load controller through storyboard
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Override point for customization after application launch. // 1. create window self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; // 2. load main. storyboard // name: storyboard name does not need to be suffixed with UIStoryboard * storyboard = [UIStoryboard storyboardWithName: @ "Main" bundle: nil]; // load the storyboard controller // The Controller pointed to by the default loading arrow // UIViewController * vc = [storyboard instantiateInitialViewController]; // load the Controller UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier: @ "blue"]; // sets the window's root controller self. window. rootViewController = vc; // 3. display window [self. window makeKeyAndVisible]; return YES ;}
Create a controller through xib
// Step for xib to attach a controller // xib must have a view to describe which view in the Controller // which describes the Controller view in xib, and must be connected // to establish a connection between the xib and the Controller, tell xib to describe the controller self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; ViewController * vc = [[ViewController alloc] initWithNibName: @ "vc" bundle: nil]; self. window. rootViewController = vc; [self. window makeKeyAndVisible];
Load controller using loadview Method
Underlying implementation: determines whether a specified storyboard exists. If yes, the view of the Controller described in storyboard is created. If not, an empty view is created.
// Function: load the view of the controller. Call time: When the view of the controller is used for the first time, the call // BGView is the newly created object inherited from the UIView-(void) loadView {BGView * view = [[BGView alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. view = view; self. view. backgroundColor = [UIColor redColor];}