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

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

问题描述

我使用NSTimer在一个基于OpenGL的iPhone应用程序中做一些渲染。我有一个模态对话框,弹出并请求用户输入。当用户提供输入时,我想暂停,例如:

  [myNSTimer pause]; 

我使用这种语法,因为我一直在做:

  [myNSTimer invalidate]; 

解决方案

从这里开始:



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



您可以存储定时器启动后经过的时间...当定时器开始存储日期在NSDate变量然后当用户切换...使用方法timeIntervalSinceNow在NSDate类存储已经过去了多少时间...注意,这将给一个负值timeIntervalSinceNow当用户返回使用该值



我不认为有办法暂停和重新启动计时器,我也遇到了类似的情况。


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];

when I want it to stop.

How can I programmatically pause the NSTimer?

解决方案

From here:

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

"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天全站免登陆