【问题标题】:How to detect when user tap on Shift key and Shift mode in iOS?如何检测用户何时点击 iOS 中的 Shift 键和 Shift 模式?
【发布时间】:2013-05-25 04:41:50
【问题描述】:
我可以使用UITextViewDelegate 或NSNotificationCenter 来检测用户何时点击Keyboard 上的字符键向UITextView 输入文本。
但是我的应用需要检测用户何时点击Shift key,我还想检测哪个Shift mode is activated。这意味着我想检测用户何时输入小写、大写第一个字符或大写所有字符模式。
我搜索了很多,但找不到好的解决方案。请帮忙!
【问题讨论】:
标签:
ios
objective-c
uitextview
uikeyboard
【解决方案1】:
一种可能的解决方案是植入您自己的自定义键盘(也可能需要自定义文本视图),因为目前似乎没有公共 API 在 iOS 上公开此信息。
【解决方案2】:
你不能对 A 到 Z 的键进行正则表达式检查吗?
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
// check if string entered matches regular expression [A-Z]
if(matchedRegularExpression)
{
NSLog(@"uppercase character detected");
}
else
{
NSLog(@"lowercase character detected");
}
return true;
}