暂停并恢复NSTimer [英] pause and resume NSTimer

查看:121
本文介绍了暂停并恢复NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中使用NSTimer播放视频,NSTimer连续运行以在函数
中运行我如何暂停&恢复NSTimer的行动,我的行动是 -

I'm using NSTimer in my program to play video, NSTimer run continuously to run in the function how I'm pause & resume NSTimer in action, my action is-

-(void)handleTap
{
    if(pause==YES)
    {
      //resume ;
    }
    else
    {
      //pause;
    }
}


推荐答案

那里在NSTimer中没有暂停和恢复功能。您可以执行以下提到的代码。

There is no pause and resume functionality in NSTimer. You can do like below mentioned code.

- (void)startTimer {
    m_pTimerObject = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(fireTimer:) userInfo:nil repeats:YES];
}
- (void)fireTimer:(NSTimer *)inTimer {
    // Timer is fired.
}
- (void)resumeTimer {
     if(m_pTimerObject) {
         [m_pTimerObject invalidate];
         m_pTimerObject = nil;        
 }
 m_pTimerObject = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(fireTimer:) userInfo:nil repeats:YES];
}
- (void)pauseTimer {
    [m_pTimerObject invalidate];
    m_pTimerObject = nil;
}

我希望这段代码片段能为您提供帮助。

I hope this code snippets will help you.

这篇关于暂停并恢复NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆