防止文本字段中的自定义键盘 [英] Prevent custom keyboard in textfield

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

问题描述

我正在尝试自定义键盘如何影响我的应用。我在我的iPhone 6上安装了Swype。

I was experimenting with how a custom keyboard affects my app. I installed Swype on my iPhone 6.

我发现在我的一些视图中我在文本字段上设置了自定义inputView属性,Swype键盘覆盖并呈现而不是我的选择器。这完全打破了我的用户界面,不能被允许。

I find that in some of my views where I have custom inputView property set on a text field, the Swype keyboard is overriding and presenting instead of my picker. This completely breaks my UI and cannot be allowed.

有没有办法明确告诉iOS 8只使用我设置的inputView?

Is there a way to explicitly tell iOS 8 only to use the inputView I have set?

这可能是个错误吗?允许第三方覆盖我的输入规范是不是完全没有预期的行为?

Is this a bug, perhaps? It is not at all expected behavior to allow a third party to override my input spec?

推荐答案

使用来自Pablo Ezequiel Romero的答案作为一个起点,我能够让事情为我工作。基本上,不是使用 UIViewController 作为自定义键盘,而是使用 UIInputViewController 并将控件放在<$ c中$ c> UIInputViewController 的 inputView 。然后,将 UITextField UITextView inputView 分配给 UIInputViewController inputView

Using the answer from Pablo Ezequiel Romero as a starting point, I was able to get things to work for me. Essentially, rather than using a UIViewController for the custom keyboard, use a UIInputViewController and put your controls inside the UIInputViewController's inputView. Then, assign the inputView of your UITextField or UITextView to the inputView of the UIInputViewController.

如果你'重新使用自动布局,您需要确保正确设置所有内容并确保在inputView上设置初始高度约束并将其优先级设置为低于最大999级别(我使用800)。任何高度都可以;系统将用自己的约束替换你的约束。较低的优先级避免了自动布局冲突。 (对我来说,如果我没有包含这个约束,那么最终视图根本不会有任何高度。)

If you're using auto layout, you need to make sure that you set everything properly and make sure to set an initial height constraint on the inputView and set its priority below the max 999 level (I used 800). Any height will do; the system will replace your constraint with one of its own. The lower priority avoids auto layout conflicts. (For me, if I didn't include this constraint, the final view wouldn't have any height at all.)

当我做了所有这些时,我能够切换进出我的(应用内部)自定义键盘和任何第三方键盘扩展。

When I did all this, I was able to switch in and out of my (internal to the app) custom keyboard and any third-party keyboard extension.

这篇关于防止文本字段中的自定义键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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