NSTimer的启动与停止、暂停和继续

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 15:22   140   0

Timer启动:

self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(updateStepWithCusInterval) userInfo:nil repeats:YES];

Timer停止:

[self.updateTimer invalidate];


//注意,Timer的停止方法invalidate会释放该Timer对象的所有引用计数,所以引用该Timer类的对象实例不需要再对其调用release方法。

NSTimer的暂停和继续

可以用NSTimer设置访问函数的时间周期:


countTime = [NSTimerscheduledTimerWithTimeInterval:(1.0)

target:self

selector:@selector(updateBoard)

userInfo:nil

repeats:YES];


即每1秒调用一次updateBoard函数

要暂停,可以这样:

[countTime setFireDate:[NSDate distantFuture]]; 

需要继续的时候

[countTime setFireDate:[NSDate date]]; 



分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP