且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iPhone(iOS)的硬件键盘上检测键盘事件

更新时间:2022-12-24 14:44:03

一种实现此目的的方法是隐藏一个额外的(在您的情况下为第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.