Reputation: 2917
If the user has not touched the screen for a specific time, I have to do a particular action. How I can do that in Cocos2d?
Upvotes: 0
Views: 535
Reputation: 69027
You could subclass your UIView and override - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
.
This method is called very early in the responder chain and allows you to detect a touch anywhere in the view.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *result = [super hitTest:point withEvent:event];
....
return result;
}
Once you detect a touch, you reset a timer, so that either a new touch event comes in before the timer fires, or the timer fires.
When the timer fires, you execute your particular action.
A similar approach can be followed by subclassing UIWindow
and then overriding -(void)sendEvent:(UIEvent *)event
. This has the advantage of not being related to a view, but to the whole window of your app and being called even earlier in the responder chain.
- (void)sendEvent:(UIEvent *)event {
if ([self thisIsTheTouchIwaitedFor:event])
[self resetWaitTimer];
[super sendEvent:event];
}
Upvotes: 6