xcode11新建項目工程,新增了scenedelegate這個類,轉而將原appdelegate負責的對ui生命周期的處理擔子接了過來。故此可以理解為:ios 13以后,appdelegate負責處理app生命周期,scenedelegate負責處理ui生命周期的處理。
1.使用scenedelegate(ios 13以下黑屏)
如果創建app支持的最低版本是ios13,可以考慮直接使用。
舉例使用系統底部欄:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
- ( 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 新建項目工程內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/Harvey_DHui/article/details/105454318