我想在我的自定义键盘上使用自动更正和快捷方式列表,例如默认英文键盘.我检查了输入键盘文档,但不知道如何使用它.
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 与 requestSupplementaryLexiconWithCompletion 一起使用?
实现词典看起来很像这样:
Implementing the lexicon would look pretty much like this:
requestSupplementaryLexiconWithCompletion()
在启动时获取词典一次.NSString
(跟踪当前单词)requestSupplementaryLexiconWithCompletion()
to get the lexicon upon launch once.NSString
(tracking the current word)此外,您还可以使用 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 的个人体验
这篇关于如何在 iOS8 自定义键盘中使用自动更正和快捷键列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!