如何使用return / enter键创建UIKeyCommand?

时间:2014-02-25 22:21:53

标签: ios objective-c ios7 uiresponder uikeycommand

我想制作仅使用UIKeyCommand密钥的[return]。到目前为止,我已经尝试过:

UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)];

输入键没有全局常量,例如up,down,left,right和escape(来自UIResponder.h):

// These are pre-defined constants for use with the input property of UIKeyCommand objects.
UIKIT_EXTERN NSString *const UIKeyInputUpArrow         NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputDownArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputLeftArrow       NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputRightArrow      NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const UIKeyInputEscape          NS_AVAILABLE_IOS(7_0);

还有什么我可以尝试捕获return / enter键吗?

1 个答案:

答案 0 :(得分:30)

使用@"\r"回车而不是@"\n"换行应该有效。