更新时间:2023-01-01 12:27:26
虽然这个问题相当陈旧,但Apple已经在iOS 7中添加了对键盘特定快捷方式的支持。查看 UIKeyCommand类,用于硬件键盘快捷键的特殊支持。我们的高级步骤是:
While this question is fairly old, Apple has added support for keyboard specific shortcuts in iOS 7. Check out the UIKeyCommand class in the UIKit Framework for special support for hardware keyboard shortcuts. The high level steps for us are:
keyCommandWithInput:modifierFlags:action:
UIKeyCommand
类上的方法,用于为带有修饰符的指定键创建 UIKeyCommand
的实例。请注意,系统处理的任何键盘快捷键(如Command-C for copy)都不起作用。您还将传递将在使用键盘快捷键时调用的操作选择器 UIKeyCommand
与您的响应器对象相关联(s)从响应者对象的 keyCommand
属性中返回它们。 keyCommandWithInput:modifierFlags:action:
method on the UIKeyCommand
class to create an instance of the UIKeyCommand
for the specified keys with modifiers. Note that any keyboard shortcuts handled by the system (like Command-C for copy) will not work. You will also pass an action selector that will be called when the keyboard shortcut is usedUIKeyCommand
with your responder object(s) by returning them from the responder object's keyCommand
property.