22 lines
735 B
Swift
22 lines
735 B
Swift
import UIKit
|
||
import SwiftUI
|
||
|
||
/// 场景代理:以 UIHostingController 承载 SwiftUI 根视图(UIKit 与 SwiftUI 混用)
|
||
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||
|
||
var window: UIWindow?
|
||
|
||
func scene(_ scene: UIScene,
|
||
willConnectTo session: UISceneSession,
|
||
options connectionOptions: UIScene.ConnectionOptions) {
|
||
guard let windowScene = scene as? UIWindowScene else { return }
|
||
|
||
let window = UIWindow(windowScene: windowScene)
|
||
let hosting = UIHostingController(rootView: ContentView())
|
||
hosting.view.backgroundColor = .black
|
||
window.rootViewController = hosting
|
||
window.makeKeyAndVisible()
|
||
self.window = window
|
||
}
|
||
}
|