Man*_*nav 88
您需要执行以下步骤:
var window:UIWindow?如果 AppDelegate 中不存在,您还需要添加
Ngu*_*uấn 54
SceneDelegate.swift文件Application Scene Manifest从Info.plist文件中删除var window: UIWindow?到 AppDelegate.swift@main用。。。来代替@UIApplicationMainUISceneSession Lifecycle( 函数 ) 中AppDelegatemil*_*czi 23
它是使用 Xcode 生成的空项目的完整解决方案(带故事板)
SceneDelegate.swift文件Application Scene Manifest从Info.plist文件中删除AppDelegate.swift文件中
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window:UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
window?.makeKeyAndVisible()
return true
}
}
Run Code Online (Sandbox Code Playgroud)
Ami*_*ant 14
var window: UIWindow?您的 AppDelegate 类作为实例属性@main用属性替换@UIApplicationMain属性(这保存为手动创建和分配窗口)以下是更改后 AppDelegate 的外观:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
要添加到已接受的答案:您还需要在 AppDelegate 中写入:
self.window = UIWindow(frame: UIScreen.main.bounds)
let controller = MyRootViewController()
window?.rootViewController = controller
window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)