美文网首页iOS开发
Xcode11探索之旅

Xcode11探索之旅

作者: 萌小奇 | 来源:发表于2019-11-05 14:42 被阅读0次

    在更新到Xcode11、iOS13之后,对原有项目进行适配各种操作。
    最近需求一个全新的APP,才发现Xcode11变了很多,再也不是我印象中的那个TA了。

    • Xcode11添加启动图片
    • Xcode11纯代码创建初始页

    Xcode11添加启动图片

    首先感谢网上各位大神。

    新建LaunchImage

    Launch.png

    拖入UI给的符合尺寸的图片

    选择新建的启动图片

    Xcode11中,在target里边的App Icons and Launch Images,没有了Launch Images Source选项。

    AppImage.png

    解决方法

    Launch Screen File置为空。

    在工程targets-->Build Settings 搜索 Asset Catalog Launch Image Set Name,然后设置成新建的启动页名称即可。

    警告⚠️

    需要注意到一个警告:

    alert.png

    从2020年4月开始,使⽤ iOS13 SDK 的 App 将必须提供 LaunchScreen,而LaunchImage将退出历史的舞台,说明以后启动页要通过LaunchScreen来设置了。

    Xcode11纯代码创建初始界面

    删除工程中main.storyboard

    • 区别一:项目中除了有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文件中对应的键值

    • 区别二:info.plist文件中main.storyboard的引用位置发生了改变

    因为iOS13之后出现了UISceneDelegate,main变为UISceneDelegate目录下,如下图。

    删掉StoryboardName键值对。

    如果只删除main.storyboard,会报如下的错误:

    Could not find a storyboard named 'Main' in bundle NSBundle

    删掉TARGETS中main的引用

    方法一:使用UISceneDelegate

    SceneDelegate.m中写入window初始化代码

    警告⚠️

    原来初始化window的代码如下:

        //实例化window
        self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        //手写项目需要初始化开始页面:
        ViewController *mainView = [[ViewController alloc] init];
        self.window.rootViewController = mainView;
        [self.window makeKeyAndVisible];
    

    如果还用initWithFrame方法,运行项目,会出现启动页之后变成了黑屏。

    正确的初始化方法是initWithWindowScene

        UIWindowScene *windowScene = (UIWindowScene *)scene;
        //实例化window
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        self.window.backgroundColor = [UIColor whiteColor];
        //手写项目需要初始化开始页面:
        ViewController *mainView = [[ViewController alloc] init];
        self.window.rootViewController = mainView;
        [self.window makeKeyAndVisible];
    

    如下图所示

    方法二:使用原有的AppDelegate(UIApplicationDelegate)

    • 删掉SceneDelegate.h和SceneDelegate.m文件
    • 删掉info.plist文件中关于UISceneDelegate的键值
    • 在APPdelegate.m中,注释掉关于UISceneDelegate的初始代码。

    注释掉如下图所示代码:

    • 在AppDelegate.h中添加window属性

    @property (strong, nonatomic) UIWindow * window;

    之后的操作和改版之前一样。

    相关文章

      网友评论

        本文标题:Xcode11探索之旅

        本文链接:https://www.haomeiwen.com/subject/vznsbctx.html