[英]Adding new UIWindow to the scene on iOS13
I'm adding new UIWindow to show passcode view controller when the app is entering foreground. 当应用程序进入前台时,我将添加新的UIWindow以显示密码视图控制器。
Before iOS 13 in AppDelegate I had property var passcodeWindow = UIWindow(frame: UIScreen.main.bounds)
where my rootViewController
was the passcode view controller and in applicationWillEnterForeground
method I was doing passcodeWindow.makeKeyAndVisible()
to place it on the top. 在iOS 13之前的AppDelegate中,我具有
var passcodeWindow = UIWindow(frame: UIScreen.main.bounds)
属性,其中我的rootViewController
是密码视图控制器,在applicationWillEnterForeground
方法中,我正在执行passcodeWindow.makeKeyAndVisible()
将其放在顶部。
Now when I want to implement the passcode functionality in iOS 13 there is a problem with this approach. 现在,当我想在iOS 13中实现密码功能时,这种方法就会出现问题。 I moved it to the
sceneWillEnterForeground
method in SceneDelegate, but it seems like I can't show passcodeWindow
on top of the actual window in this scene. 我将其移至
sceneWillEnterForeground
中的sceneWillEnterForeground
方法,但似乎无法在该场景的实际窗口顶部显示passcodeWindow
。
I do it exactly the same as in AppDelegate and the passcodeWindow
is not shown. 我执行的操作与AppDelegate中的操作完全相同,并且未显示
passcodeWindow
。
The way I do it in sceneWillEnterForeground
in AppDelegate and in SceneDelegate: 我在AppDelegate和SceneDelegate中的
sceneWillEnterForeground
中做到的方式:
passcodeWindow.rootViewController = passcodeViewController(type: .unlock)
passcodeWindow.makeKeyAndVisible()
I expect passcodeWindow
to show on the top of current window in the scene. 我希望
passcodeWindow
可以显示在场景中当前窗口的顶部。
You can try this: 您可以尝试以下方法:
if #available(iOS 13.0, *) {
if let currentWindowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
passcodeWindow.windowScene = currentWindowScene
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.