如何在 iphone 中暂停和恢复 NSTimer [英] how to pause and resume NSTimer in iphone

查看:46
本文介绍了如何在 iphone 中暂停和恢复 NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我正在开发小游戏应用程序.当用户转到另一个视图[说设置视图]时,我需要暂停计时器.当用户返回该视图时,我需要恢复计时器.

hello I am developing small gameApp. I need to pause the timer,when user goes to another view [say settings view]. when user comes back to that view , I need to resume the timer.

谁能解决这个问题...

can anybody solve this issue ...

在此先感谢...

推荐答案

你不能暂停计时器.但是,当用户进入设置视图时,您可以保存计时器的 fireDate 以及当前日期.在此之后,您使计时器无效并让用户做他/她的事情.一旦他/她切换回游戏,您创建一个新的计时器对象并将触发日期设置为旧触发日期加上用户在菜单中的时间(oldTime + currentTime).

You can't pause a timer. However, when the user goes to the settings view, you can save the fireDate of the timer and also the current date. After this you invalidate the timer and let the user do his/her stuff. Once he/she switches back to the game, you create a new timer object and set the fire date to the old fire date plus the time the user was in the menu (oldTime + currentTime).

这篇关于如何在 iphone 中暂停和恢复 NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆