2013-07-09 30 views
0

我正在使用scheduleTimerWithTimeInterval:每N秒执行一次动画。(重新)scheduleTimerWithInterval可能吗?

在某些情况下,我想重新安排的事情所以N重新开始述说即

schduleTimerWithTimeInterval:5

后5秒5秒后执行操作

执行操作

2秒自上次动作起经过一段时间后,发生X事件

自X以来5秒, orm动作(即不是5并以秒为最后的执行动作)

5秒后5秒后执行操作

执行操作

所以,当X发生时,是否有可能重新设定scheduleTimerWithTimeInterval?

回答

1

因此,像这样:

self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(takeAShot) userInfo:nil repeats:YES]; 

,然后当x发生:

[self.timer invalidate]; 
self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(takeAShot) userInfo:nil repeats:YES]; 

或用重复和非重复计时器

任何方式
相关问题