如何实现新的 iPad Pro 键盘快捷键功能?

How can I implement the new iPad Pro Keyboard Shortcuts feature?

Apple's iPad Pro page 谈论新的键盘快捷键功能:

Shortcuts at your fingertips.

iOS 9 works seamlessly with the Smart Keyboard, adding a variety of useful QuickType features to your iPad Pro.

Time-saving Shortcuts

Use keyboard shortcuts to perform even more commands on your iPad Pro — like switching between apps or bringing up search with your Smart Keyboard. And interact with your apps using their own built-in custom shortcuts. Just press and hold a key like Command, Option, or Control to see shortcuts in any app.

我尝试搜索 iOS 9 and iOS 9.1 API 页面,但找不到任何关于键盘快捷键的信息。

如何在我的应用程序中实现此功能,或者在哪里可以找到讨论它的文档?

从 iOS 7 开始,这个功能的大部分似乎已经存在,称为 UIKeyCommand

唯一添加的是 discoverabilityTitle,它用于显示任何 iPad 运行 iOS 9+ 上可用的命令名称。您可以在任何提供键盘快捷键的屏幕(例如 iOS 主屏幕)上按住命令键,在模拟器中看到此菜单。

关于此有一个 nice write up on NSHipster,其中包括 iOS 9 个功能。

基本上您需要执行以下操作:

  1. 允许视图控制器成为第一响应者。
  2. Return 视图控制器的 keyCommands 方法中的 UIKeyCommand 数组。
  3. 处理发送到视图控制器的操作。