转载自:http://blog.csdn.net/chentoo/article/details/8667918
那,API里面NSTimer 是木有暂停继续的方法的,只有fire和invalidate,前者是开工的意思,后者是废掉的意思,如果用废掉来代替暂停的功能?显然是不对的。
那肿么办呢? 暂停: [timer setFireDate:[NSDate distantFuture]]; distantFuture,就是问你未来有多远呢?好远好远就是无法到达的时间,所以 timer就一直等待不 fire了。也就是暂停了。 继续: [timer setFireDate:[NSDate date]]; 这个当然就是把fire 的时间设置为当前时刻,所以timer就立刻开工啦! 完事!
------------------------------------------------------------------------------
http://www.cnblogs.com/crazyac/articles/2497477.html
可以用NSTimer设置访问函数的时间周期: countTime = [NSTimerscheduledTimerWithTimeInterval:(1.0/60.0) target:self selector:@selector(updateBoard) userInfo:nil repeats:YES];
即每1/60秒调用一次updateBoard函数 但是有时候游戏里要暂停,可以这样: [countTime setFireDate:[NSDate distantFuture]]; 需要继续的时候 [countTime setFireDate:[NSDate date]];
|
|