iOS: How to access the `UIKeyboard`?(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
初始化一个虚拟视图,并将其设置为 UITextField的
inputAccessoryView
代码> 或 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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS:如何访问“UIKeyboard"?


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01