-
1.main函数
-
2.UIApplicationMain
-
创建UIApplication对象
-
创建UIApplication的delegate对象
- 3.delegate对象开始处理(监听)系统事件(没有storyboard)
-
程序启动完毕的时候, 就会调用代理的application:didFinishLaunchingWithOptions:方法
-
在application:didFinishLaunchingWithOptions:中创建UIWindow
-
创建和设置UIWindow的rootViewController
-
显示窗口
3.根据Info.plist获得最主要storyboard的文件名,加载最主要的storyboard(有storyboard)
-
创建UIWindow
-
创建和设置UIWindow的rootViewController
-
显示窗口
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
//第三个参数:设置是应用程序对象的名称UIApplication或者是它的子.如果是nil,默认是UIApplication
//第四个参数:设置UIApplication代理的名称
//NSStringFromClass:将类名转成字符串
return UIApplicationMain(argc, argv, NSStringFromClass([UIApplication class]), NSStringFromClass([AppDelegate class]));
}
}
/*
1.执行main函数.
2.执行UIApplicationMain,创建UIApplication对象,并设置UIApplication它的代理.
3.开启了一个事件循环.(主运行循环,死循环:保证应用程序不退出)
4.去加载info.plist.(判断info.plist当中有没有Mian,如果有,加载Mian.storyBoard)
5.应用程序启动完毕.(通知代理应用程序启动完毕)
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//1.创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//2.设置窗口的根控制器
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor redColor];
self.window.rootViewController = vc;
//3.显示窗口
[self.window makeKeyAndVisible];
//从ios9之后,如果添加了多个窗口,控制器它会自动把状态栏给隐藏掉.
//解决办法,把状态栏给应用程序管理.
self.window1 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 375, 20)];
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor blueColor];
self.window1.rootViewController = vc1;
[self.window1 makeKeyAndVisible];
//设置窗口层级
//UIWindowLevelAlert > UIWindowLevelStatusBar > UIWindowLevelNormal
self.window1.windowLevel = UIWindowLevelStatusBar;
self.window.windowLevel = UIWindowLevelAlert;
//键盘,状态栏其实都是window
UITextField *textF = [[UITextField alloc] init];
self.textF = textF;
[textF becomeFirstResponder];
//UITextField想要显示键盘,必须得要添加到一个View上,
[vc.view addSubview:textF];
return YES;
}
网友评论