简体   繁体   English

使用UITextField自定义键盘扩展

[英]Custom Keyboard extension with UITextField

I have custom keyboard extension with UITextField in it. 我有自定义键盘扩展名,里面有UITextField。 I am able switch to UITextField 's text input, but cannot switch back to self.textDocumentProxy . 我可以切换到UITextField的文本输入,但无法切换回self.textDocumentProxy Does anybody know, how to do something like [self.textDocumentProxy becomeFirstResponder] ? 有谁知道,如何做[self.textDocumentProxy becomeFirstResponder]类的事情?

(By the way, it looks like "GIF Keyboard" app provides such possibility) (顺便说一句,它看起来像“GIF键盘”应用程序提供这种可能性)

I've implemented next workaround for this: 我为此实现了下一个解决方法:

  1. My textFied inherits from UITextField . 我的textFied继承自UITextField UserInteraction disabled to prevent it from becomeFirstResponder (because you are not able switch back to system input). 禁用UserInteraction以防止它成为becomeFirstResponder (因为您无法切换回系统输入)。 I've added blinking UIView as cursor imitation ( blinking animation ). 我添加了闪烁的UIView作为光标模仿( 闪烁动画 )。 Change this cursor origin.x in overwrited setText: method by calculating length of current string (use boundingRectWithSize: method for this). 通过计算当前字符串的长度,在覆盖的setText:方法中更改此游标origin.x (对此使用boundingRectWithSize:方法)。

  2. 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. 当用户键入的内容我正在检查textField是否处于活动状态(显示),然后相应地向textField (使用setText: insertText:self.textDocumentProxy insertText: / deleteBackward方法添加/删除符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM