如何以编程方式暂停 NSTimer? [英] How can I programmatically pause an NSTimer?

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

问题描述

我正在使用 NSTimer 在基于 OpenGL 的 iPhone 应用程序中进行一些渲染.我有一个弹出并请求用户输入的模式对话框.当用户提供输入时,我想暂停",即像这样:

I'm using an NSTimer to do some rendering in an OpenGL based iPhone app. I have a modal dialog box that pops up and requests user input. While the user is providing input I'd like to "pause" i.e. something like this:

[myNSTimer pause];

我使用这种语法是因为我一直在做这样的事情:

I'm using this syntax because I've been doing things like:

[myNSTimer invalidate];

当我想要它停止时.

如何以编程方式暂停 NSTimer?

How can I programmatically pause the NSTimer?

推荐答案

从这里:

http://discussions.apple.com/thread.jspa?threadID=1811475&tstart=75

"您可以存储自计时器启动以来经过的时间量...当计时器启动时将日期存储在 NSDate 变量中.然后当用户切换时...使用 NSDate 类中的 timeIntervalSinceNow 方法来存储已经过去了多少时间...请注意,这将为 timeIntervalSinceNow 提供一个负值.当用户返回时,使用该值来设置适当的计时器.

"You can store the amount of time that has passed since the timer started... When the timer starts store the date in an NSDate variable. Then when the user switches... use the method timeIntervalSinceNow in the NSDate class to store how much time has passed... note that this will give a negative value for timeIntervalSinceNow. When the user returns use that value to set an appropriate timer.

我认为没有办法暂停和重新启动计时器.我也遇到过类似的情况."

I don't think there's a way to pause and restart a timer. I faced a similar situation. "

这篇关于如何以编程方式暂停 NSTimer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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