【发布时间】:2019-03-13 14:33:10
【问题描述】:
我正在尝试将键盘快捷键添加到我的应用程序中,但我遇到了 UIKeyCommand 操作未被调用的问题。
我有一个 UIViewController 覆盖了 KeyCommands。
- (BOOL)becomeFirstResponder
{
return YES;
}
- (NSArray<UIKeyCommand *> *)keyCommands
{
return self.keyCommandManager.keyShortcutsArray;
}
我还有一个 NSObject 的 KeyCommandManager 类,它有两种方法,一种是根据我的应用程序的状态设置 keyShortcutsArray,另一种是应该由 UIKeyCommands 触发的方法。
- (void)setKeyShortcutsOfType:(ShortcutType)shortcutType
{
switch(shortcutType)
{
case PlaybackPreviewShortcut:
self.keyShortcutsArray = @[[UIKeyCommand keyCommandWithInput:@" " modifierFlags:0 action:@selector(keyShortcutActions:) discoverabilityTitle:@"Toggle playback preview"]];
break;
default:
self.keyShortcutsArray = @[];
break;
}
- (void)keyShortcutActions:(UIKeyCommand)sender
{
NSLog(@"#### This method is not being called by the space key shortcut");
}
当前,当按下某个键时,KeyCommand 覆盖方法正在获取正确的数组。但是,这些键的选择器不起作用,并且没有调用 keyShortcutActions 方法。
【问题讨论】:
标签: ios objective-c