1. 程式人生 > 程式設計 >ios 使用xcode11 新建專案工程的步驟詳解

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 配置資訊

ios 使用xcode11 新建專案工程的步驟詳解

第二步:刪除 SceneDelegate 類檔案

ios 使用xcode11 新建專案工程的步驟詳解

第三步:還原 AppDelegate 的 UIWindow 屬性。

ios 使用xcode11 新建專案工程的步驟詳解

第四步:刪除 AppDelegate.m 中的方法

ios 使用xcode11 新建專案工程的步驟詳解

至此,可以像往常一樣在 AppDelegate類中的 didFinishLaunchingWithOptions 方法中寫UI 執行程式碼。

總結

到此這篇關於ios 使用xcode11 新建專案工程的步驟詳解的文章就介紹到這了,更多相關ios xcode11 新建專案工程內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!