ios 使用xcode11 新建項目工程的步驟詳解
xcode11新建項目工程,新增了scenedelegate這個類,轉而將原Appdelegate負責的對UI生命周期的處理擔子接了過來。故此可以理解為:ios 13以后,Appdelegate負責處理App生命周期,scenedelegate負責處理UI生命周期的處理。
1.使用scenedelegate(iOS 13以下黑屏)
如果創建app支持的最低版本是ios13,可以考慮直接使用。
舉例使用系統底部欄:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //1.創建Tab導航條控制器 UITabBarController *tabControl = [[UITabBarController alloc] init]; tabControl.tabBar.barStyle = UIBarStyleBlack; //2.創建相應的子控制器(viewcontroller) ViewController *control = [[ViewController alloc] init]; control.tabBarItem = [[UITabBarItem alloc] initWithTitle:@'first' image:[UIImage imageNamed:@'icon_contact_normal'] selectedImage:[UIImage imageNamed:@'icon_contact_normal']]; UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController: control]; ViewController2 *control2 = [[ViewController2 alloc] init]; control2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@'first' image:[UIImage imageNamed:@'icon_contact_normal'] selectedImage:[UIImage imageNamed:@'icon_contact_normal']]; UINavigationController * nav2 = [[UINavigationController alloc]initWithRootViewController: control2]; //將Tab導航條控制器設為window根控制器 self.window.rootViewController = @[nav, nav2]; //顯示window [self.window makeKeyAndVisible]; }
2.如果要適配iOS 13以下的設備,需要把相關的scenedelegate刪掉才能正常使用。分四個步驟:
第一步: 刪除 Info.plist 里面的 SceneDelegate 配置信息
第二步:刪除 SceneDelegate 類文件
第三步:還原 AppDelegate 的 UIWindow 屬性。
第四步:刪除 AppDelegate.m 中的方法
至此,可以像往常一樣在 AppDelegate類中的 didFinishLaunchingWithOptions 方法中寫UI 執行代碼。
總結
到此這篇關于ios 使用xcode11 新建項目工程的步驟詳解的文章就介紹到這了,更多相關ios xcode11 新建項目工程內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
