IOS Window視窗使用

來源:互聯網
上載者:User

標籤:並且   對象   它的   finish   sdi   window   需要   har   決定   

 

 

// 程式啟動完畢之後就會調用一次- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    // 1.建立UIWindow    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // 設定UIWindow的背景顏色    self.window.backgroundColor = [UIColor redColor];    // 讓UIWindow顯示出來(讓視窗成為主視窗 並且顯示出來)    // 一個應用程式只能有一個主視窗    [self.window makeKeyAndVisible];    // 讓UIWindow成為主視窗//    [self.window makeKeyWindow];        // 2. 再建立一個視窗    UIWindow *w2 = [[UIWindow alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];    w2.backgroundColor = [UIColor yellowColor];    [w2 makeKeyAndVisible];    self.w2 = w2;            // 3.建立兩個文本輸入框    // 3.1將文本輸入框添加到window中    UITextField *tx1 = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 200, 40)];    tx1.borderStyle = UITextBorderStyleRoundedRect;    [self.window addSubview:tx1];        // 3.2將文本輸入框添加到w2中    UITextField *tx2 = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 100, 40)];    tx2.borderStyle = UITextBorderStyleRoundedRect;    [self.w2 addSubview:tx2];        // 擷取應用程式的主視窗    NSLog(@"%@", [UIApplication sharedApplication].keyWindow);    return YES;}- (void)test{    // 1.建立UIWindow    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // 2.設定UIWindow的背景顏色    self.window.backgroundColor = [UIColor redColor];        // 建立控制器    // NJViewController *vc = [[NJViewController alloc] init];    // 將控制器的view添加到UIWindow上    // 問題1:當view發生一些事件的時候,通知控制器, 但是控制器以及銷毀了,所以可能出現未知錯誤    /*     問題2:當發生旋轉事件的時候 UIApplication對象會將旋轉事件傳遞給UIWindow     UIWindow又會將旋轉事件傳遞它的根控制器,由根控制器決定是否需要旋轉          UIApplication->UIWindow->根控制器     */    // [self.window addSubview:vc.view];    // 設定UIWindow的根控制器(建議使用下面這種方式)    // self.window.rootViewController = vc;    //     UISwitch *switchBtn = [[UISwitch alloc] init];    //    [self.window addSubview:switchBtn];        // 3.讓UIWindow顯示出來(讓視窗成為主視窗 並且顯示出來)    // 一個應用程式只能有一個主視窗    [self.window makeKeyAndVisible];    // 讓UIWindow成為主視窗    //    [self.window makeKeyWindow];}

 

IOS Window視窗使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.