iOS 7で解決策を探している人には、keyCommandsという新しいUIResponderプロパティがあります。 UITextViewのサブクラスを作成し、次のようにkeyCommandsを実装...
@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
{
}
'UIWebView'でも使えますか? – Dmitry
@Altaveron keyCommandsプロパティはUIResponderのプロパティであり、UIWebViewはUIResponderを継承しているため、うまくいかない理由はありません。 – amergin
'UIWebView'は多くのサブビューのコンテナです。 – Dmitry