如何在iOS8自定义键盘中使用自动更正和快捷列表

如何在iOS8自定义键盘中使用自动更正和快捷列表

本文介绍了如何在iOS8自定义键盘中使用自动更正和快捷列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用自定义和快捷列表,如默认英语键盘和我的自定义键盘。
我检查键盘文档,但不知道如何使用它。

I want to use the autocorrection and shortcut list like default English keyboard with my custom keyboard.I check the in keyboard document but don't know how to use it.

在。

每个自定义键盘(独立于其RequestsOpenAccess键的值)都可以通过UILexicon类访问基本的自动更正词典。利用此类以及您自己设计的词典,在用户输入文本时提供建议和自动更正。 UILexicon对象包含来自各种来源的单词,包括:

Every custom keyboard (independent of the value of its RequestsOpenAccess key) has access to a basic autocorrection lexicon through the UILexicon class. Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections as users are entering text. The UILexicon object contains words from various sources, including:


  • 用户通讯簿数据库中不成对的名字和姓氏

  • 设置>常规>键盘>快捷方式列表中定义的文本快捷方式

  • 常用字词词典

如何在Objective-C中访问我们字典中的快捷列表和输入?

如何使用UILexicon with requestSupplementaryLexiconWithCompletion?

推荐答案

实现词典看起来非常像这样:

Implementing the lexicon would look pretty much like this:


  1. 使用 requestSupplementaryLexiconWithCompletion()在启动时获取词典。

  2. 输入每种类型的文本将其添加到 NSString (跟踪当前单词)

  3. 当用户按空格时(结尾的单词) )检查词典中的词典

  4. 如果匹配c数量字符数并删除该字符数

  5. 输入词典建议的建议

  6. 清除字符串并重新开始

  1. Use requestSupplementaryLexiconWithCompletion() to get the lexicon upon launch once.
  2. Each type text is inputted add it to a NSString (tracking the current word)
  3. When user presses space (end of curent word) check the string against the lexicon
  4. If it's a match count the number of characters and delete that number of characters
  5. Input the suggestion suggested by the lexicon
  6. Clear the string and start again

此外,您还可以使用 UITextChecker 来提供更高级的自动更正功能。

Additionally you could also use UITextChecker to offer more advanced auto-correct features.

代码(在Objective-C中,这可能不是我在公共汽车上用SO写的100%准确但它应该这样做):

Code (in Objective-C, this may not be 100% accurate I wrote in SO while on the bus but it should do):

UILexicon *lexicon;
NSString *currentString;

-(void)viewDidLoad {
     [self requestSupplementaryLexiconWithCompletion:^(UILexicon *receivedLexicon) {
         self.lexicon = receivedLexicon;
     }];
}

-(IBAction)myTypingAction:(UIButton *)sender {
    [documentProxy insertText:sender.title];
    [currentString stringByAppendingString:sender.title];
}

-(IBAction)space {
   [documentProxy insertText:@" "];
   for (UILexiconEntry *lexiconEntry in lexicon.entries) {
       if (lexiconEntry.userInput isEqualToString:currentString) {
            for (int i = 0; currentString.length >=i ; i++) {
                 [documentProxy deleteTextBackwards];
            }
            [documentProxy insertText:lexiconEntry.documentText];
            currentString = @"";
        }
    }
}

如果你愿意发表评论还有其他问题。

Feel free to comment if you have any more questions.

来源:iOS 8键盘和UILexicon的个人体验

Source: Personal experience with iOS 8 keyboards and UILexicon

这篇关于如何在iOS8自定义键盘中使用自动更正和快捷列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:04