[绍棠] xcode11新项目删除main.storyboard

就是用xcode11新建iOS项目后,想要删除默认的main.storyboard,使用自定义的window和controller的坑。

具有一定经验的人想必都知道Xcode11之前,想要达到上面的目的步骤吧。首先就是选中工程文件选项,之后删除Main Interface选项里的Main,如下图:

之后在Appdelegate的didFinishLaunchingWithOptions方法中自定义window并设置为keyWindow和让它显示,如下图:

就这么简单的实现了。

然鹅随着iOS13的推出,在之前AppDelegate的基础上多出了一个SceneDelegate,会将AppDelegate里的lifecycle的那些代理方法转交给SceneDelegate,就是通过AppDelegate里以下两个方法实现的

以下的内容是摘自苹果官方文档:

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不用你直接去创建对象,你可以用UIApplication里的requestSceneSessionActivation:userActivity:options:errorHandler:方法,这个方法会帮你初始化一个基于info.plist文件里的默认configuration的session对象。

因此xcode11中要实现自己的没有默认main.storyboard的项目,就得将SceneDelegate里的lifecycle转交给AppDelegate,按照上面所说,这一步操作就是,删除或注释一下截图里的两个方法

接近着删除在info.plist里的Application Scene Manifest条目

之后就是xcode11以前的常规操作了,首先,删除info.plist里的Main storyboard file base name条目

之后在AppDelegate.swift里添加window属性,因为xcode默认删除了这个属性,现在你需要将它重新添加回来才行,如果是OC写的话,就在AppDelegate.h里添加这个window属性。


 

发布了179 篇原创文章 · 获赞 24 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/happyshaotang2/article/details/103368089