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; }