在更新到Xcode11、iOS13之后,對原有項(xiàng)目進(jìn)行適配各種操作。
最近需求一個全新的APP,才發(fā)現(xiàn)Xcode11變了很多,再也不是我印象中的那個TA了。
- Xcode11添加啟動圖片
- Xcode11純代碼創(chuàng)建初始頁
Xcode11添加啟動圖片
首先感謝網(wǎng)上各位大神。
新建LaunchImage

拖入U(xiǎn)I給的符合尺寸的圖片
選擇新建的啟動圖片
Xcode11中,在target里邊的App Icons and Launch Images,沒有了Launch Images Source選項(xiàng)。

解決方法
將Launch Screen File置為空。
在工程targets-->Build Settings 搜索 Asset Catalog Launch Image Set Name,然后設(shè)置成新建的啟動頁名稱即可。

警告??
需要注意到一個警告:

從2020年4月開始,使? iOS13 SDK 的 App 將必須提供 LaunchScreen,而LaunchImage將退出歷史的舞臺,說明以后啟動頁要通過LaunchScreen來設(shè)置了。
Xcode11純代碼創(chuàng)建初始界面
刪除工程中main.storyboard
- 區(qū)別一:項(xiàng)目中除了有APPdelegate.h和APPdelegate.m文件,還有了Scenedelegate.h和Scenedelegate.m文件。
In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-based app.
iOS13版本之后,AppDelegate(UIApplicationDelegate)控制生命周期的行為交給了SceneDelegate(UIWindowSceneDelegate)
這個場景,如果不使用iPad的多窗口不建議使用.

刪掉info.plist文件中對應(yīng)的鍵值
- 區(qū)別二:info.plist文件中main.storyboard的引用位置發(fā)生了改變
因?yàn)閕OS13之后出現(xiàn)了UISceneDelegate,main變?yōu)閁ISceneDelegate目錄下,如下圖。

刪掉StoryboardName鍵值對。
如果只刪除main.storyboard,會報(bào)如下的錯誤:
Could not find a storyboard named 'Main' in bundle NSBundle
刪掉TARGETS中main的引用

方法一:使用UISceneDelegate
在SceneDelegate.m中寫入window初始化代碼
警告??
原來初始化window的代碼如下:
//實(shí)例化window
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//手寫項(xiàng)目需要初始化開始頁面:
ViewController *mainView = [[ViewController alloc] init];
self.window.rootViewController = mainView;
[self.window makeKeyAndVisible];
如果還用initWithFrame方法,運(yùn)行項(xiàng)目,會出現(xiàn)啟動頁之后變成了黑屏。
正確的初始化方法是initWithWindowScene
UIWindowScene *windowScene = (UIWindowScene *)scene;
//實(shí)例化window
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.backgroundColor = [UIColor whiteColor];
//手寫項(xiàng)目需要初始化開始頁面:
ViewController *mainView = [[ViewController alloc] init];
self.window.rootViewController = mainView;
[self.window makeKeyAndVisible];
如下圖所示

方法二:使用原有的AppDelegate(UIApplicationDelegate)
- 刪掉SceneDelegate.h和SceneDelegate.m文件

- 刪掉info.plist文件中關(guān)于UISceneDelegate的鍵值

- 在APPdelegate.m中,注釋掉關(guān)于UISceneDelegate的初始代碼。
注釋掉如下圖所示代碼:

- 在AppDelegate.h中添加window屬性
@property (strong, nonatomic) UIWindow * window;
之后的操作和改版之前一樣。