程序的入口及AppDelegate窗体显示原理

AppDelegate.m

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    self.window.backgroundColor = [UIColor redColor];
    
    /*
     makeKeyAndVisible的作用:
     1.让window在屏幕上直接显示,这是window的属性。view没有这个属性,假设室view,须要加入到其它的视图上显示
     2.将当前窗体设置为主窗体
     */
    [_window makeKeyAndVisible];
    
    _window.windowLevel = UIWindowLevelStatusBar;
    
    UIWindow *w2 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
    w2.backgroundColor = [UIColor greenColor];
//    [w2 makeKeyAndVisible];   不能这么写
    
    //hidden的作用:在主窗体上显示w2,可是w2不是主窗体
    w2.hidden = NO;
    
    /*
     设置window的优先级:UIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert;
     默认是:UIWindowLevelNormal
     */
    w2.windowLevel = UIWindowLevelAlert;
    
    //拿到当前程序的主window
    UIWindow *w3 = application.keyWindow;
    NSLog(@"self.window:%@",self.window);
    NSLog(@"w3:%@",w3);
    
    
    return YES;
}


posted @ 2017-08-03 21:13  gccbuaa  阅读(151)  评论(0编辑  收藏  举报