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
{
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…