使用UITextField自定义键盘扩展 [英] Custom Keyboard extension with UITextField

查看:166
本文介绍了使用UITextField自定义键盘扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自定义键盘扩展名,其中包含UITextField。我可以切换到 UITextField 的文本输入,但无法切换回 self.textDocumentProxy 。有谁知道,怎么做像 [self.textDocumentProxy becomeFirstResponder]

I have custom keyboard extension with UITextField in it. I am able switch to UITextField's text input, but cannot switch back to self.textDocumentProxy. Does anybody know, how to do something like [self.textDocumentProxy becomeFirstResponder]?

(顺便说一下,它看起来像GIF键盘应用提供了这样的可能性)

(By the way, it looks like "GIF Keyboard" app provides such possibility)

推荐答案

我为此实现了下一个解决方法:

I've implemented next workaround for this:


  1. 我的 textFied 继承自 UITextField UserInteraction 已禁用,以防止它来自 becomeFirstResponder (因为您无法切换回系统输入)。我添加了闪烁 UIView 作为光标模仿(闪烁动画) 。通过计算当前字符串的长度,在被覆盖的 setText:方法中更改此光标 origin.x (使用 boundingRectWithSize:此方法。)

  1. My textFied inherits from UITextField. UserInteraction disabled to prevent it from becomeFirstResponder (because you are not able switch back to system input). I've added blinking UIView as cursor imitation (blinking animation). Change this cursor origin.x in overwrited setText: method by calculating length of current string (use boundingRectWithSize: method for this).

当用户输入我要检查的内容时,如果 textField 处于活动状态(显示),然后添加/删除符号到 textField (带 setText:)或 self.textDocumentProxy insertText: / deleteBackward 相应的方法。

When user types something I am checking if textField is active (showed) and then adding/removing symbols to textField (with setText:) or self.textDocumentProxy insertText:/deleteBackward methods accordingly.

这篇关于使用UITextField自定义键盘扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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