iOS:如何访问`UIKeyboard`? [英] iOS: How to access the `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
初始化虚拟视图,并将其设置为<$ c的 inputAccessoryView
$ c> UITextField 或 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屋!