提示:项目创建后,会自动生成与Scene相关的文件或设置,真让人头疼啊,刚开始很不习惯,甚至说还没时间去学习它,暂时放一边吧,还是用老一套舒服;那么,如何删除呢?
文章目录 前言一、SceneDelegate是什么?二、剔除Scene总结前言
iOS13.0 版本以上, AppDelegate 获取window时,会直接报错‘Value of type 'AppDelegate' has no member 'window'’,这就D疼了~
SceneDelegate是啥
一、SceneDelegate是什么?简单来说,iOS 13中引入了场景的概念,所有的UI生命周期都将由场景来管理。
本文主讲如何脱离Scene;
二、剔除Scene 1.删除SceneDelegate.swift。 2.AppDelegate删除带有Scene一词的相关方法。 3.info.plist中删除Main storyboard file base name与Application Scene Manifest两项。 4.AppDelegate.swift改动一下代码入口;直接贴。1. var window: UIWindow?
2. 初始化window
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = .white
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
完整的AppDelegate.siwft:
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = .white
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
return true
}
}
总结
思路:删除场景代理> info.plist移除场景、Main.storyboard项>AppDelegate代码改写
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)