使用UITextField自定义键盘扩展 [英] Custom Keyboard extension with 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:
-
我的
textFied
继承自UITextField
。UserInteraction
已禁用,以防止它来自becomeFirstResponder
(因为您无法切换回系统输入)。我添加了闪烁UIView
作为光标模仿(闪烁动画) 。通过计算当前字符串的长度,在被覆盖的setText:
方法中更改此光标origin.x
(使用boundingRectWithSize:
此方法。)
My
textFied
inherits fromUITextField
.UserInteraction
disabled to prevent it frombecomeFirstResponder
(because you are not able switch back to system input). I've added blinkingUIView
as cursor imitation (blinking animation). Change this cursororigin.x
in overwritedsetText:
method by calculating length of current string (useboundingRectWithSize:
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屋!