简体   繁体   English

iPhone:计时器暂停并继续吗?

[英]iPhone:Timer pause and resume?

My game application is having a timer(starting from 0:00 then increases) when it is is running. 我的游戏应用程序正在运行时有一个计时器(从0:00开始,然后增加)。 For that i use, NSTimer and then int hrVal = (timeCount/60)*60; 为此我使用NSTimer然后int hrVal =(timeCount / 60)* 60; int minVal = ((timeCount/60)*60)+9; int minVal =((timeCount / 60)* 60)+9; etc code. 等代码。

At some point of time, lets say user wins one level, i am showing a winning alert, at this point of time, i need to Pause the timer and resume again once user clicked OK button from this alert. 在某个时间点,可以说用户赢得了一个级别,我正在显示获胜警报,在这个时间点上,我需要暂停计时器,并在用户单击此警报中的“确定”按钮后再次恢复。 Is it possible to do that and How? 有可能做到这一点,怎么做?

I would appreciate if some one help me on this ! 如果有人帮助我,我将不胜感激!

Thanks. 谢谢。

Instead of starting and stopping the timer you could set a BOOL pause = YES and then do nothing in the method that the timer fires while it is YES. 除了启动和停止计时器外,您可以设置BOOL pause = YES ,然后在计时器为YES时触发计时器的方法中不执行任何操作。 When the pause ends set it back to NO. 暂停结束后,将其设置回NO。

完成某个级别后,您可以invalidate计时器invalidate ,并为下一个级别创建一个新的定时器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM