0

在 iOS 15 中,键盘处理发生了变化。除了通常keyCommands的程序员重写之外,还必须为自己的命令分配比系统命令更高的优先级。

因此,以下代码适用于我:

final class MyViewController: UIViewController {

    override var keyCommands: [UIKeyCommand]? {
        let action = UIKeyCommand(input: UIKeyCommand.inputUpArrow, modifierFlags: [], action: #selector(myAction))
        if #available(iOS 15, *) {
            action.wantsPriorityOverSystemBehavior = true
        }
        return [action]
    }
    // rest of the code
}

另一方面,几乎相同的代码但继承自QLPreviewController 不起作用

final class PreviewViewController: QLPreviewController {
    // same internals as above
}

在视图层次结构中,我发现实际上有某种额外的导航,也许是偷了我的键盘按键,也许这就是上面的代码不起作用的原因。

在此处输入图像描述


有谁知道如何解决或解决此问题?显然,额外的导航来自 Apple,我无法访问这些额外提供的控制器。

我试图打印以下详细信息,但都没有帮助:

print(presentedViewController ?? "none") // output: none
print(topMostViewController) // output: <MyApp.PreviewViewController: 0x7fbe44156203>
print(inputViewController ?? "none") // output: none

值得添加我也尝试添加方法

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("test?")
    super.pressesBegan(presses, with: event)
}

并且test永远不会出现在控制台中,无论我按下什么按钮。很明显,其他东西窃取了按键。这在 iOS 15 之前并没有发生。

4

0 回答 0