在更新到Xcode11雄卷、iOS13之后熄驼,對(duì)原有項(xiàng)目進(jìn)行適配各種操作。
最近需求一個(gè)全新的APP劝赔,才發(fā)現(xiàn)Xcode11變了很多誓焦,再也不是我印象中的那個(gè)TA了。
- Xcode11添加啟動(dòng)圖片
- Xcode11純代碼創(chuàng)建初始頁(yè)
Xcode11添加啟動(dòng)圖片
首先感謝網(wǎng)上各位大神着帽。
新建LaunchImage
拖入U(xiǎn)I給的符合尺寸的圖片
選擇新建的啟動(dòng)圖片
Xcode11中杂伟,在target
里邊的App Icons and Launch Images
,沒(méi)有了Launch Images Source
選項(xiàng)仍翰。
解決方法
將Launch Screen File
置為空赫粥。
在工程targets
-->Build Settings
搜索 Asset Catalog Launch Image Set Name
,然后設(shè)置成新建的啟動(dòng)頁(yè)名稱即可予借。
警告??
需要注意到一個(gè)警告:
從2020年4月開(kāi)始越平,使? iOS13 SDK 的 App 將必須提供 LaunchScreen,而LaunchImage將退出歷史的舞臺(tái)灵迫,說(shuō)明以后啟動(dòng)頁(yè)要通過(guò)LaunchScreen來(lái)設(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)
這個(gè)場(chǎng)景,如果不使用iPad的多窗口不建議使用.
刪掉info.plist文件中對(duì)應(yīng)的鍵值
- 區(qū)別二:info.plist文件中main.storyboard的引用位置發(fā)生了改變
因?yàn)閕OS13之后出現(xiàn)了UISceneDelegate利凑,main變?yōu)閁ISceneDelegate目錄下浆劲,如下圖。
刪掉StoryboardName鍵值對(duì)哀澈。
如果只刪除main.storyboard牌借,會(huì)報(bào)如下的錯(cuò)誤:
Could not find a storyboard named 'Main' in bundle NSBundle
刪掉TARGETS中main的引用
方法一:使用UISceneDelegate
在SceneDelegate.m
中寫(xiě)入window初始化代碼
警告??
原來(lái)初始化window的代碼如下:
//實(shí)例化window
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//手寫(xiě)項(xiàng)目需要初始化開(kāi)始頁(yè)面:
ViewController *mainView = [[ViewController alloc] init];
self.window.rootViewController = mainView;
[self.window makeKeyAndVisible];
如果還用initWithFrame
方法,運(yùn)行項(xiàng)目割按,會(huì)出現(xiàn)啟動(dòng)頁(yè)之后變成了黑屏膨报。
正確的初始化方法是initWithWindowScene
UIWindowScene *windowScene = (UIWindowScene *)scene;
//實(shí)例化window
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.backgroundColor = [UIColor whiteColor];
//手寫(xiě)項(xiàng)目需要初始化開(kāi)始頁(yè)面:
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;
之后的操作和改版之前一樣现柠。