【发布时间】:2020-01-07 02:08:00
【问题描述】:
如果 App 进入前台,我们会尝试将当前 View 重置为 Root。
我们如何在 SwiftUI 中做到这一点?
func sceneWillEnterForeground(_ scene: UIScene) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let contentView = RootView().environment(\.managedObjectContext, context)
if let windowScene = scene as? UIWindowScene {
let singleOrder = SingleOrder()
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView.environmentObject(singleOrder))
self.window = window
window.makeKeyAndVisible()
}
}
【问题讨论】:
标签: swiftui