如果用户在特定时间内没有触摸屏幕,我必须执行特定操作。我如何在 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/