I need to perform a particular action in a view controller when user don't touch a particular screen for 3 seconds.
How can I do that in iOS?
I need to perform a particular action in a view controller when user don't touch a particular screen for 3 seconds.
How can I do that in iOS?
Override the view's touches began method and reset a timer when you get touches.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.timer invalidate];
self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(inactivityTimerFired) userInfo:nil repeats:NO];
[super touchesBegan:touches withEvent:event];
}
You could target the view controller instead of self
if you need to.
NSTimer
property/ivar to your view controllertouchesBegan:
)3.0
s to call a functionnil