如何响应外部键盘箭头键? [英] How can I respond to external keyboard arrow keys?
问题描述
我知道之前已经问过这个问题,我看到的唯一答案是不需要外部键盘,因为它违反了UI指南。但是,我想使用这样的脚踏板: http://www.bilila.com/page_turner_for_ipad 在我的应用程序中的页面之间切换(除了刷卡)。此页面特纳模拟键盘并使用向上/向下箭头键。
I know this has been asked before, and the only answers I've seen are "Don't require an external keyboard, as it goes against UI guidelines". However, I want to use a foot pedal like this: http://www.bilila.com/page_turner_for_ipad to change between pages in my app (in addition to swiping). This page turner emulates a keyboard and uses the up/down arrow keys.
所以这是我的问题:我如何回应这些箭头键事件?它必须可以像其他应用程序一样管理,但我要画一个空白。
So here is my question: how do I respond to these arrow key events? It must be possible as other apps manage, but I'm drawing a blank.
推荐答案
对于那些正在寻找解决方案的人在iOS 7下 - 有一个名为keyCommands的新UIResponder属性。创建UITextView的子类并实现keyCommands,如下所示...
For those who are looking for a solution under iOS 7 - there is a new UIResponder property called keyCommands. Create a subclass of UITextView and implement keyCommands as follows...
@implementation ArrowKeyTextView
- (id) initWithFrame: (CGRect) frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (NSArray *) keyCommands
{
UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputUpArrow modifierFlags: 0 action: @selector(upArrow:)];
UIKeyCommand *downArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputDownArrow modifierFlags: 0 action: @selector(downArrow:)];
UIKeyCommand *leftArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputLeftArrow modifierFlags: 0 action: @selector(leftArrow:)];
UIKeyCommand *rightArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputRightArrow modifierFlags: 0 action: @selector(rightArrow:)];
return [[NSArray alloc] initWithObjects: upArrow, downArrow, leftArrow, rightArrow, nil];
}
- (void) upArrow: (UIKeyCommand *) keyCommand
{
}
- (void) downArrow: (UIKeyCommand *) keyCommand
{
}
- (void) leftArrow: (UIKeyCommand *) keyCommand
{
}
- (void) rightArrow: (UIKeyCommand *) keyCommand
{
}
这篇关于如何响应外部键盘箭头键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!