how to pause and resume NSTimer in iphone

前端 未结 7 1624
逝去的感伤
逝去的感伤 2020-12-06 11:07

hello I am developing small gameApp. I need to pause the timer,when user goes to another view [say settings view]. when user comes back to that view , I need to resume the

7条回答
  •  独厮守ぢ
    2020-12-06 11:36

    on Start - 
    startNewCapture = [NSDate date];
    
    on Pause - 
    captureSessionPauseDate = [NSDate date]; 
    captureSessionTimeInterval = [captureSessionPauseDate timeIntervalSinceDate:startNewCapture];
    
    on Resume - 
    NSDate *dateNow = [NSDate date];
    startNewCapture = [NSDate dateWithTimeInterval:-captureSessionTimeInterval sinceDate:dateNow];
    

提交回复
热议问题