【问题标题】:How to detect when user tap on Shift key and Shift mode in iOS?如何检测用户何时点击 iOS 中的 Shift 键和 Shift 模式?
【发布时间】:2013-05-25 04:41:50
【问题描述】:

我可以使用UITextViewDelegateNSNotificationCenter 来检测用户何时点击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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多