美文网首页
iOS【Swift简单去掉SceneDelegate】

iOS【Swift简单去掉SceneDelegate】

作者: NJ_墨 | 来源:发表于2020-06-02 11:02 被阅读0次

    将多出来的文件和代码删除就好了

    删除SceneDelegate代理文件 (可选)
    删除 Info.plist里面的Application Scene Manifest配置(一定要删除)
    删除 AppDelegate代理的两个方法:
    application:configurationForConnectingSceneSession:options:
    application: didDiscardSceneSessions:
    这两个方法一定要删除,否则使用纯代码创建的不会生效。
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
            window?.backgroundColor = UIColor.white;
            window = UIWindow(frame: UIScreen.main.bounds);
    
            let tabbar = MainTabBarCtrl();
            window?.rootViewController = tabbar;
            window?.makeKeyAndVisible()
            return true
    }
    

    代码虽然执行了,不显示自己的内容。可能是window显示出问题了

    查看iOS13下UIWindow的定义,有这么一条

    // If nil, window will not appear on any screen.
    // changing the UIWindowScene may be an expensive operation and should not be done in performance-sensitive code
    @property(nullable, nonatomic, weak) UIWindowScene *windowScene API_AVAILABLE(ios(13.0));
    

    如果UIWindow的属性windowScene为nil,那么这个UIWindow则不会显示在任何屏幕上。

    相关文章

      网友评论

          本文标题:iOS【Swift简单去掉SceneDelegate】

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