我有一个NSTimer
以 3 秒的间隔触发以减少值。当我执行增加该值的操作时,我想重新启动计时器,从该点开始计时 3 秒。
例如,如果我增加该值并且计时器将在 1 秒内触发,我想更改它并让计时器在 3 秒内触发。我可以使计时器无效并重新创建它吗?或者我可以用setFireDate:
,使用当前日期并添加 3 秒的间隔?
是的,您可以使其无效。并再次创建它。
您还可以使用:
- (void) myTimedTask {
// other stuff this task needs to do
// change the variable varyingDelay to be 1s or 3s or... This can be an instance variable or global that is changed by other parts of your app
// weStillWantTimer is also a similar variable that your app uses to stop this recurring task
if (weStillWantTimer)
[self performSelector:@selector(myTimedTask:) withObject:gameColor afterDelay:varyingDelay];
}
您调用 myTimedTask 来启动重复任务。一旦启动,您可以使用不同的 Delay 更改延迟或使用 weStillWantTimer 停止它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)