简体   繁体   English

如何检测用户在iOS中点按Shift键和Shift模式?

[英]How to detect when user tap on Shift key and Shift mode in iOS?

I can use UITextViewDelegate or NSNotificationCenter to detect when user tap character key on Keyboard to input text to UITextView . 我可以使用UITextViewDelegateNSNotificationCenter来检测用户在Keyboard上点击字符键何时向UITextView输入文本。

But my App need to detect when user tap on Shift key and I also want to detect which Shift mode is activated . 但我的应用程序需要检测用户何时点击Shift key ,我还想检测哪个Shift mode is activated It's mean I want to detect when user gonna to type in lower case, Upper first character or Upper all characters mode. 这意味着我想要检测用户何时输入小写,上部第一个字符或上部所有字符模式。

I search so much but can't find good solution. 我搜索了这么多,但找不到好的解决方案。 Please help! 请帮忙!

一种可能的解决方案是植入您自己的自定义键盘(也可能需要自定义文本视图),因为目前似乎没有公开API在iOS上公开此信息。

Can't you do a regular expression check for keys of A to Z ? 你不能对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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM