I\'m using an NSTimer to do some rendering in an OpenGL based iPhone app. I have a modal dialog box that pops up and requests user input. While the user is providing input
You cant pause NSTimer as mentioned above. So the time to be captured should not be dependent on Timer firedate ,i suggest. Here is my simplest solution :
When creating the timer initialize the starting unit time like:
self.startDate=[NSDate date];
self.timeElapsedInterval=[[NSDate date] timeIntervalSinceDate:self.startDate];//This ``will be 0 //second at the start of the timer.``
myTimer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:self `selector:@selector(updateTimer) userInfo:nil repeats:YES];
` Now in the update timer method:
NSTimeInterval unitTime=1;
-(void) updateTimer
{
if(self.timerPaused)
{
//Do nothing as timer is paused
}
else{
self.timerElapsedInterval=timerElapsedInterval+unitInterval;
//Then do your thing update the visual timer texfield or something.
}
}