使用UILexicon在iOS 8键盘扩展中实现自动更正 [英] Using UILexicon to implement autocorrect in iOS 8 Keyboard Extension

查看:461
本文介绍了使用UILexicon在iOS 8键盘扩展中实现自动更正的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过这个问题已被问过几次,但似乎没有人有答案。我试图在自定义键盘上创建一个自动更正功能,但我完全迷失了如何这样做。 Apple提供了一些文档,但它不是很详细。我知道它与UILexicon数据有关,但我不知道如何处理它以及如何使用它来纠正用户输入的文本字符串。



非常感谢任何帮助。



到目前为止我找到了什么:

  let controller = UIInputViewController()

controller.requestSupplementaryLexiconWithCompletion({
lexicon in

println(lexicon.description)

})

但这是就在我得到的时候。不知道该怎么做。

解决方案

你问的是一个非常棘手的问题。简而言之,iOS8上没有内置的自动更正权限;在iOS上也无法访问API,允许系统执行诸如显示红色可能错误下划线效果或系统自动更正行为的其他方面,例如in-放置建议对话框(在iOS 7上,或者如果您没有可见的建议栏)或将更正蓝色背景(在iOS 8上)。



你不能做的事情:





就地错误指示





就地自动更正对话框





建议栏自动更正指标



可以做的是从头开始编写自己的自动更正引擎,包括你自己的文本处理和分析以及你自己的用户界面习语。这一切都必须通过您无法在键盘边界之外绘制的限制来完成,并且您无法修改屏幕上的任何其他内容。许多第三方键盘都是这样做的,例如 minuum swiftkey (免责声明:我在minuum上工作),但这是非偶然的工作量。如果你有兴趣玩这个,一个好的起点可能是内置的 UITextChecker 类,尽管自动更正最终是一个与拼写检查不同的问题。 / p>

UILexicon 只有在您已经实施之后才有用;它真正为您提供的是一个单词列表,您可以使用它来补充您正在使用的任何字典,以及实现您的用户可能在其系统设置中添加的任何文本快捷方式。它本身并不足以建立一个自动修正系统。



附录:
如何编写拼写校正器是Peter Norvig写的一篇很棒的小文章/教程,你可能觉得有趣,而且我即使你试图写自动更正,也会推荐。


I've seen that this question has been asked a few times, but no one seems to have an answer. I am trying to create an autocorrect feature on a custom keyboard, but I am completely lost as to how to do so. Apple gives some documentation, but it's not very detailed. I know it has something to do with UILexicon data, but I'm not sure what to do with it and how to use it to correct strings of text the user is typing.

Any help would be greatly appreciated.

What I have found so far:

let controller = UIInputViewController()

    controller.requestSupplementaryLexiconWithCompletion({
        lexicon in

        println(lexicon.description)

    })

But this is as far as I've gotten. Not sure what to do from here.

解决方案

You are asking a very difficult question. In short, there is no built in access to autocorrect on iOS8; there is also no access to the APIs on iOS that allow the system to do things like show the red 'possible error' underline effect, or to other aspects of the system autocorrect behaviour, such as the in-place suggestion dialog (on iOS 7, or if you do not have the suggestions bar visible) or the 'will correct' blue background (on iOS 8).

things you can't do:

in-place error indicator

in-place autocorrect dialog

suggestions bar autocorrect indicator

what you can do is write your own autocorrect engine, from scratch, including both your own text processing and analysis and your own user-interface idioms. This has to all be done with the limitation that you are not able to draw outside of your keyboard's bounds, and you cannot modify anything else on screen. A number of third-party keyboards do this, such as minuum and swiftkey (disclaimer: I work on minuum) but it is a non-incidental amount of work. If you're interested in playing around with this, a good place to start might be the built in UITextChecker class, although auto-correction is ultimately a problem distinct from spell-checking.

UILexicon is only useful once you've already implemented things; all that it really offers you is a list of words that you can use to supplement whatever dictionary you're using, as well as to implement any text shortcuts your user might have added in their system settings. It is not, on its own, enough to build an auto-correction system from.

addendum: How to Write a Spelling Corrector is a great little essay / tutorial by Peter Norvig that you might find interesting, and that I would recommend even if you're not trying to write auto-correct.

这篇关于使用UILexicon在iOS 8键盘扩展中实现自动更正的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆