iPhone键盘触摸事件
我需要能够检测键盘上的触摸事件。我有一个应用程序显示在一段时间不活动(即没有触摸事件)后出现的屏幕为了解决这个问题,我对 UIWindow 进行了子类化并实现了 sendEvent 函数,这使我可以通过以下方式获取整个应用程序上的触摸事件在一个地方实施该方法。除了出现键盘并且用户在键盘上打字之外,这在任何地方都有效。我需要知道的是,有没有一种方法可以检测键盘上的触摸事件,有点像 uiWindow 中的 sentEvent 所做的那样。提前致谢。
I need to be able to detect touch events on the keyboard. I have an app which shows a screen which occurs after a certain period of inactivity (i.e. no touch events) To solve this issue, I have subclassed my UIWindow and implemented the sendEvent function, which allows me to get touch events on the whole application by implementing the method in one place. This works everywhere beside when the keyboard is presented and the user is typing on the keyboard. What I need to know is that is there a way to detect touch events on the keyboard, kind of like what sentEvent does for uiWindow. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了问题的解决方案。如果您观察到以下通知,则您可以在按下该键时收到事件。我在自定义 uiwindow 类中添加了这些通知,因此在一个地方执行此操作将允许我在整个应用程序中获取这些触摸事件。
无论如何,希望它对其他人有帮助。
found a solution to the problem. if you observe the following notifications, you are able to get an event when the key is pressed. I added these notifications in my custom uiwindow class so doing it at one place will allow me to get these touch events throughout the application.
anyways, hope it helps someone else.
iPhoneDev:这就是我正在做的事情。
我有一个自定义 UIWindow 对象。在这个对象中,有一个 NSTimer,每当有触摸时就会重置。要获得此触摸,您必须重写 UIWindow 的 sendEvent 方法。
这就是我的自定义窗口类中的 sendEvent 方法的样子:
这是resetIdleTimer:
在此之后,在idleTimerExceeded 中,我向窗口委托(在本例中为appDelegate)发送一条消息。
当我在 appDelegate 中创建此自定义窗口对象时,我将 appDelegate 设置为该窗口的委托。在idleTimeLimitExceeded 的appDelegate 定义中,我在计时器到期时执行必须执行的操作。他们的关键是创建自定义窗口并覆盖 sendEvent 函数。将此与上面显示的两个键盘通知结合起来,我在自定义窗口类的 init 方法中添加了这些通知,您应该能够在应用程序中的任何位置获取屏幕上 99% 的触摸事件。
iPhoneDev: here is what I am doing.
I have a custom UIWindow object. In this object, there is a NSTimer that is reset whenever there is a touch. To get this touch you have to override the sendEvent method of UIWindow.
this is what the sendEvent method looks like in my custom window class:
here is the resetIdleTimer:
after this, in the idleTimerExceeded, I send a message to the window delegates, (in this case, the appDelegate).
When I create this custom window object in the appDelegate, I set the appDelegate as the delegate for this window. And in the appDelegate definition of idleTimeLimitExceeded is where I do what I have to when the timer expires. They key thing is the create the custom window and override the sendEvent function. Combine this with the two keyboard notification shown above I added in the init method of the custom window class and you should be able to get 99% of all touch events on screen anywhere in the application.