如何检测 iPhone 屏幕键盘上的触摸
我试图检测用户在打字时触摸键盘上的按键的时间,例如,当按下某个键足够长的时间时,我会弹出一个对话框。
通过测量 touchesEnded
和 touchesBegan
之间的时间来检测常规视图的这一点很简单。但是,我没有从键盘收到任何事件。关于如何从键盘接收 touchesEnded
和 touchesBegan
事件有什么想法吗?
I'm trying to detect how long a user is touching a key on a keyboard when she is typing, so that, for instance, I popup a dialog when a certain key is pressed for a long enough time.
Detecting this for a regular view is trivial with measuring the time between touchesEnded
and touchesBegan
. However, I don't receive any events from the keyboard. Any ideas on how one can receive touchesEnded
and touchesBegan
events from the keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法将您想要的内容添加到系统提供的键盘中。但是,您可以通过实现自己的自定义键盘来实现您想要的目的,该键盘可以具有您想要处理长按键的任何方法。请参阅上一个问题作为如何实现自定义键盘的示例。
实现此操作时,您应该使用 iOS 提供的 UILongPressGestureRecognizer。
You cannot add what you want to the system-provided keyboard. However, you could achieve what you want by implementing your own custom keyboard, which could have whatever methods you wanted to handle long key presses. See previous this previous question as one example of how to approach implementing a custom keyboard.
When implementing this, rather than examining touchesEnded and touchesBegan to identify when a long touch occurred, you should the iOS-provided UILongPressGestureRecognizer.
我不相信你能够做到这一点(特别是在应用程序商店应用程序中),因为系统本身有额外的菜单,当按住某些键时会显示,甚至可能没有屏幕键盘(蓝牙键盘) 。
I don't believe you will be able to do this (esp. in an App Store app) as the system itself has extra menus it displays when holding down on certain keys and there may not even be an on screen keyboard (bluetooth keyboard).
将这些添加到 TextField 的侦听器中
您还可以使用这些通知来了解键盘何时显示和隐藏:
Add these to listeners to your TextField
You can also use these notifications that knows when the keyboard shows and hides: