objective-c - 检测用户在特定时间内没有触摸屏幕

标签 objective-c ios cocoa-touch cocos2d-iphone touch

如果用户在特定时间内没有触摸屏幕,我必须执行特定操作。我如何在 Cocos2d 中做到这一点?

最佳答案

您可以子类化您的 UIView 并覆盖 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

此方法在响应链的早期被调用,允许您检测 View 中任何位置的触摸。

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
     UIView *result = [super hitTest:point withEvent:event];
     ....
     return result;
 }

一旦检测到触摸,就重置计时器,以便在计时器触发之前有新的触摸事件进入,或者计时器触发。

当计时器触发时,您执行特定的操作。

可以通过子类化 UIWindow 然后覆盖 -(void)sendEvent:(UIEvent *)event 来遵循类似的方法。这样做的好处是不与 View 相关,而是与应用程序的整个窗口相关,甚至可以在响应者链中更早地被调用。

 - (void)sendEvent:(UIEvent *)event {
     if ([self thisIsTheTouchIwaitedFor:event])
         [self resetWaitTimer];
     [super sendEvent:event];
 }

关于objective-c - 检测用户在特定时间内没有触摸屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6568447/

相关文章:

objective-c - 'hash'方法在Objective-C中做什么

ios - 无法通过 AVAudioPlayer 中的 URL 播放声音

java - 使用 Java 中的 Obj-C 类,有办法吗?

ios - 使用核心数据进行应用程序设置

ios - 如何在 Objective-C 中使用后台线程?

ios - UIWebView IBOutlet 连接问题

ios - Sharekit 试飞和 pod

iOS swift : Generic array cast to array of subclass

iphone - 如何在iPhone SDK中设置音频文件或录制的音频文件的音高?

iphone - -[NSCFString objectAtIndex :]: unrecognized selector