iPhone 上的键盘和起床状态
如何判断键盘是否已打开?
我有一个 UISearchbar 实例,它成为第一响应者。
当键盘出现时,通知会作为 API 的一部分发送出去,但我不想立即对此做出回应。我可以用布尔状态记录它,但这看起来很笨拙。我想知道是否有“吸气剂”,我可以打电话询问。
How do I find out if the keyboard is up?
I have a UISearchbar instance which becomes the first responder.
When the keyboard appears a notification is sent out as part of the API, however I don't want to respond to this right away. I could record this in a boolean state, but that seems clunky. I'd like to know if there is a "getter" some where I can call to find out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我就是这样做的:
KeyboardStateListener.h
KeyboardStateListener.m
然后用它来计算其余的:
This is how I do it:
KeyboardStateListener.h
KeyboardStateListener.m
Then use this to figure out the rest:
我能想到的唯一可靠的方法就是按照你说的去做。使用这样的通知:
然后
除此之外,您也许可以迭代视图子视图并查找键盘,例如:
但我不确定当 SDK 更改时这是否会中断...
也许使用此方法并添加窗口的一个类别,以便您始终可以向窗口询问键盘......只是一个想法。
The only sure way that I can think to do it as you said. using notifications like this:
and then
Other than that, you may be able to iterate through your views subviews and look for the keyboard like:
But I am not sure if this will break when the SDK changes ...
Maybe use this method and add a category to the window so that you can just always ask the window for the keyboard ... just a thought.