swift - iOS 13 isKeyWindow 总是返回 nil

标签 swift ios13 uiapplication keywindow uiscene

我想知道为什么:

UIApplication.shared.windows.first { $0.isKeyWindow } 

在模拟器和设备上总是返回 nil。您可以通过在任何 View Controller 的 viewDidLoad 中放置一个断点并将对象打印到控制台来确认这一点。
po UIApplication.shared.windows.first { $0.isKeyWindow } 

我可以获得“keyWindow”的唯一方法是获取
UIApplication.shared.windows.first

但是没有明确提到它是关键。如果 iPad 分屏 View 中有我的应用程序的多个实例怎么办?

有任何想法吗?

我的想法是,如果只有一个窗口,默认情况下它是关键,如果您在 iPad 上运行多个窗口,则当前与之交互的窗口将成为关键窗口,但是,我尚未对此进行测试。

最佳答案

你试过这个吗?

UIApplication.shared.windows.filter {$0.isKeyWindow}.first

关于swift - iOS 13 isKeyWindow 总是返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59231707/

相关文章:

web-audio-api - IOS13 是否损坏了用作连接到音频上下文的音频缓冲区的 <audio> 标签?

ios - 是否可以将替代图标应用于 iOS 应用程序?

ios - 用户强行终止应用程序 : Registering this event

iOS 启动设置 -> 限制 URL 方案

swift - 比较三个值是否相等

ios - 联系人用户界面 : how to show only specific fields when creating new contact on iOS?

ios - ios13-unSelectedItem的UITabBar tintColor不起作用

uikit - addSubView SwiftUI View to UIKit UIView in Swift

ios - 在 Swift 中从 Tableviewcell 中关闭 Popover ViewController

swift - 使用嵌入的 UINavigationController 实例化ViewController