聆听iOS应用中的所有触摸事件 [英] Listen to all touch events in an iOS app
问题描述
是否可以以某种方式聆听并捕获应用中发生的所有触摸事件?
Is it possible to somehow listen to, and catch, all the touch events occurring in an app?
我正在开发的应用将用于展厅和信息亭,因此如果在给定的几分钟内没有收到触摸,我将回到应用程序的开始部分。一种屏幕保护功能,如果你愿意的话。我打算通过在后台运行一个计时器来实现这一点,每当应用程序中的某个地方发生触摸事件时,它将被重置并重新启动。但是如何听取触摸事件?任何想法或建议?
The app I'm currently developing will be used in showrooms and information kiosks and I would therefore like to revert to the start section of the app if no touches has been received for a given couple of minutes. A sort of screensaver functionality, if you will. I'm planning to implement this by having a timer running in the background, which should be reset and restarted every time a touch event occurs somewhere in the app. But how can I listen to the touch events? Any ideas or suggestions?
推荐答案
真的很容易。
你需要一个子类 UIApplication
(让我们称之为 MyApplication
)。
You need a subclass of UIApplication
(let's call it MyApplication
).
您修改 main.m
以使用它:
return UIApplicationMain(argc, argv, @"MyApplication", @"MyApplicationDelegate");
你覆盖方法 [MyApplication sendEvent:]
:
- (void)sendEvent:(UIEvent*)event {
//handle the event (you will probably just reset a timer)
[super sendEvent:event];
}
这篇关于聆听iOS应用中的所有触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!