iOS:如何访问“UIKeyboard"? [英] iOS: How to access the `UIKeyboard`?

查看:17
本文介绍了iOS:如何访问“UIKeyboard"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到一个UIKeyboard *keyboard的指针引用到屏幕上的键盘,这样我就可以给它添加一个透明的子视图,完全覆盖它,达到禁用 UIKeyboard 而不隐藏它.

I want to get a pointer reference to UIKeyboard *keyboard to the keyboard on screen so that I can add a transparent subview to it, covering it completely, to achieve the effect of disabling the UIKeyboard without hiding it.

在这样做时,我可以假设屏幕上一次只有一个 UIKeyboard 吗?即,它是单例吗?[UIKeyboard sharedInstance] 方法在哪里.如果您通过类别实现该方法,则为布朗尼点.或者,如果你能说服我为什么只假设一个键盘并给我一个更好的解决方案是个坏主意,那么你会得到更多的分数.

In doing this, can I assume that there's only one UIKeyboard on the screen at a time? I.e., is it a singleton? Where's the method [UIKeyboard sharedInstance]. Brownie points if you implement that method via a category. Or, even more brownie points if you convince me why it's a bad idea to assume only one keyboard and give me a better solution.

推荐答案

如何使用-[UIApplication beginIgnoringInteractionEvents]?

另外,获取包含键盘的视图的另一个技巧是使用 CGRectZero 初始化一个虚拟视图,并将其设置为 UITextFieldinputAccessoryView代码> 或 UITextView.然后,获取它的 superview.尽管如此,这种恶作剧是私人的/无证的,但我听说过应用程序这样做并且无论如何都被接受了.我的意思是,Instagram 还能如何让他们的评论键盘像消息键盘一样互动(滑动时关闭)?

Also, another trick to get the view containing the keyboard is to initialize a dummy view with CGRectZero and set it as the inputAccessoryView of your UITextField or UITextView. Then, get its superview. Still, such shenanigans is private/undocumented, but I've heard of apps doing that and getting accepted anyhow. I mean, how else would Instagram be able to make their comment keyboard interactive (dismiss on swipe) like the Messages keyboard?

这篇关于iOS:如何访问“UIKeyboard"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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