【问题标题】:Adding new UIWindow to the scene on iOS13在 iOS13 的场景中添加新的 UIWindow
【发布时间】:2019-08-02 09:31:54
【问题描述】:

我正在添加新的 UIWindow 以在应用程序进入前台时显示密码视图控制器。

在 AppDelegate 中的 iOS 13 之前,我有属性 var passcodeWindow = UIWindow(frame: UIScreen.main.bounds),其中我的 rootViewController 是密码视图控制器,在 applicationWillEnterForeground 方法中,我正在使用 passcodeWindow.makeKeyAndVisible() 将其放在顶部。

现在,当我想在 iOS 13 中实现密码功能时,这种方法存在问题。我将其移至 SceneDelegate 中的 sceneWillEnterForeground 方法,但似乎无法在此场景的实际窗口顶部显示 passcodeWindow

我的做法与在 AppDelegate 中完全相同,但未显示 passcodeWindow

我在 AppDelegate 和 SceneDelegate 中的 sceneWillEnterForeground 中执行此操作的方式:

passcodeWindow.rootViewController = passcodeViewController(type: .unlock)
passcodeWindow.makeKeyAndVisible()

我希望passcodeWindow 显示在场景中当前窗口的顶部。

【问题讨论】:

  • 没有警告并且视觉调试器没有显示任何东西?
  • 当我在 passcodeWindow.makeKeyAndVisible() 之后调试时,我使用 UIApplication.shared.topViewController() 检查顶部 viewController。它说顶视图控制器是 PasscodeViewController 所以它似乎没问题。在控制台中我得到 8 次:“2019-08-02 11:44:08.466223+0200 MyProject[866:191801] [] nw_connection_receive_internal_block_invoke [C6] 接收回复失败,错误为“操作已取消””
  • 可视化调试器只显示主窗口,passcodeWindow 甚至不显示

标签: ios swift xcode ios13


【解决方案1】:

你可以试试这个:

if #available(iOS 13.0, *) {
    if let currentWindowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
        passcodeWindow.windowScene = currentWindowScene
    }
}

【讨论】:

  • 不工作,我认为这是因为没有对本地窗口实例的强引用,因此窗口显示了一秒钟,并且在下一个运行循环中由于 ARC 为 0 而释放。
  • @rockhard stackoverflow.com/a/58167743/7332815 看看这个
  • 哇,非常感谢 - @RichardLiu
  • 这是我在 iPhone 上寻找的修复程序。 @andrew54068 的链接似乎更适合显示模态,但我想要一个“浮动窗口”或各种对话框。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-08
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多