日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

xcode11新项目删除main.storyboard 两种方法

發(fā)布時間:2023/12/8 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xcode11新项目删除main.storyboard 两种方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

方法一

心急的童鞋按照老操作完成后再按照如下操作即可

?

?

/**棄用storboard1、info.plist去除<key>UIApplicationSceneManifest</key><dict><key>UIApplicationSupportsMultipleScenes</key><false/><key>UISceneConfigurations</key><dict><key>UIWindowSceneSessionRoleApplication</key><array><dict><key>UISceneConfigurationName</key><string>Default Configuration</string><key>UISceneDelegateClassName</key><string>SceneDelegate</string><key>UISceneStoryboardFile</key><string>Main</string></dict></array></dict></dict>2、啟動頁注釋 - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {// Called when a new scene session is being created.// Use this method to select a configuration to create the new scene with.return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; }- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {// Called when the user discards a scene session.// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.// Use this method to release any resources that were specific to the discarded scenes, as they will not return. }*/

?

?

具體如下:

用xcode11新建iOS項目后,想要刪除默認的main.storyboard,使用自定義的window和controller的坑。

具有一定經(jīng)驗的人想必都知道Xcode11之前,想要達到上面的目的步驟吧。首先就是選中工程文件選項,之后刪除Main Interface選項里的Main,如下圖:

?

?

?

之后在Appdelegate的didFinishLaunchingWithOptions方法中自定義window并設(shè)置為keyWindow和讓它顯示,如下圖:

?

?

就這么簡單的實現(xiàn)了。

然鵝隨著iOS13的推出,在之前AppDelegate的基礎(chǔ)上多出了一個SceneDelegate,會將AppDelegate里的lifecycle的那些代理方法轉(zhuǎn)交給SceneDelegate,就是通過AppDelegate里以下兩個方法實現(xiàn)的

?

?

?

以下的內(nèi)容是摘自蘋果官方文檔:

Overview

A?UISceneSession?object manages a unique runtime instance of your scene. When the user adds a new scene to your app, or when you request one programmatically, the system creates a session object to track that scene. The session contains a unique identifier and the configuration details of the scene. UIKit maintains the session information for the lifetime of the scene itself, destroying the session in response to the user closing the scene in the app switcher.?

You do not create session objects directly. UIKit creates sessions in response to user interactions with your app. You can also ask UIKit to create a new scene and session programmatically by calling the?requestSceneSessionActivation:userActivity:options:errorHandler:?method of?UIApplication. UIKit initializes the session with default configuration data based on the contents of your app's?Info.plist?file.

大概意思就是,一個UISceneSession不用你直接去創(chuàng)建對象,你可以用UIApplication里的requestSceneSessionActivation:userActivity:options:errorHandler:方法,這個方法會幫你初始化一個基于info.plist文件里的默認configuration的session對象。

?

?

?

因此xcode11中要實現(xiàn)自己的沒有默認main.storyboard的項目,就得將SceneDelegate里的lifecycle轉(zhuǎn)交給AppDelegate,按照上面所說,這一步操作就是,刪除或注釋一下截圖里的兩個方法

?

?

接近著刪除在info.plist里的Application Scene Manifest條目

?

?

之后就是xcode11以前的常規(guī)操作了,首先,刪除info.plist里的Main storyboard file base name條目

?

?

之后在AppDelegate.swift里添加window屬性,因為xcode默認刪除了這個屬性,現(xiàn)在你需要將它重新添加回來才行,如果是OC寫的話,就在AppDelegate.h里添加這個window屬性。

?

?

之后就在didFinishLaunch方法里初始化self.window,并設(shè)置為keywindow和讓它顯示,并初始化默認控制器即可。

?方法二

Xcode自動新增了一個SceneDelegate文件, 也就是說在iOS13中Appdelegate的作用發(fā)生了改變: iOS13之前,Appdelegate的作用是全權(quán)處理App生命周期和UI生命周期; iOS13之后,Appdelegate的作用是只處理 App 生命周期, 而UI的生命周期將全權(quán)由新增的SceneDelegate來處理.

?

SceneDelegate.m中的方法只有iOS13之后才能使用, 如果新建的項目要兼容之前的版本, 就需要自己在SceneDelegate和Appdelegate中做判斷

?

首先, UI相關(guān)的已經(jīng)不能只放在Appdelegate中, 而是區(qū)分系統(tǒng)放在SceneDelegate中處理.

其次, 要在Info.plist中刪除對應(yīng)的路徑.

?

最后, 在SceneDelegate.m中添加根控制器

?

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];UIViewController *rootVc = [[UIViewController alloc]init];rootVc.view.backgroundColor = [UIColor purpleColor];UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:rootVc];[self.window setRootViewController:rootNav];[self.window makeKeyAndVisible]; }

?


?


?

簽 名:被別人嫉妒,說明你卓越;你嫉妒別人,說明你無能。 座右銘:抓緊一切時間睡覺。

總結(jié)

以上是生活随笔為你收集整理的xcode11新项目删除main.storyboard 两种方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。