检测用户是否在特定时间内未触摸屏幕

时间:2011-07-04 07:21:09

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

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

2 个答案:

答案 0 :(得分:6)

您可以继承您的UIView并覆盖- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

此方法在响应者链中很早就被调用,并允许您在视图中的任何位置检测到触摸。

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

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

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

类似的方法可以是继承UIWindow,然后覆盖-(void)sendEvent:(UIEvent *)event。这样做的好处是不与视图相关,而是与应用程序的整个窗口相关,甚至更早地在响应程序链中调用。

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

答案 1 :(得分:0)

只是谷歌搜索我发现this也许它可以帮助你