2013-07-09 27 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]; 

或用重複和非重複計時器

任何方式
相關問題