如何在iPhone(iOS)的硬件键盘上检测键盘事件 [英] How to detect keyboard events on hardware keyboard on iPhone (iOS)
问题描述
我有一个带有登录页面的应用程序,该页面具有用于三个不同随机字符的三个字段.当用户离开最后一个字段时,软键盘消失,并且用户可以触摸屏幕上的登录"按钮.
I have an app with a login page that has three fields for three different random characters. When the user leaves the last field, the soft keyboard disappears and the user can touch a "login" button on screen.
当连接了硬件键盘(蓝牙或物理键盘)时,我希望能够按一下它的输入".但是,因为用户不在字段中,所以我看不到如何检测到该键被按下.
When there is a hardware keyboard (bluetooth or physical) attached, I'd like to be able to hit "enter" on it. However because the user is not in a field, I can't see how to detect this key being pressed.
有人会建议哪个班处理按键事件吗?大概有一个我可以用来接收这些委托的代表,但是我通过SDK进行的搜索没有发现任何东西.
Would anyone have advice on which class handles key press events? Presumably there is a delegate that I can use to receive these but my searches through the SDK haven't found anything.
谢谢
推荐答案
一种实现此目的的方法是隐藏一个额外的(在您的情况下为第4个)文本字段.使其尺寸为1x1像素且透明.然后,当其他三个文本字段中的任何一个都不存在时,使其成为第一响应者,并在该隐藏字段中查找文本更改事件以触发您的键盘输入事件.
One way to accomplish this is to have a hidden extra (4th in your case) text field. Make it 1x1 px in size and transparent. Then make it the first responder when any of your other 3 text fields are not, and look for text change events in that hidden field to trigger your key input event.
如果您不希望它也保持可见状态,您可能还需要检查显示的软件键盘通知.
You might also want to check the notification for a software keyboard appearing if you don't want it to stay visible as well.
这篇关于如何在iPhone(iOS)的硬件键盘上检测键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!