本文介绍了如何从 NSTimer 中找到剩余的时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设置了一个 NSTimer.scheduledTimerWithTimeInterval 方法,该方法每 20 分钟间隔一次.我希望能够找出应用程序进入后台模式时还剩下多少时间.我如何知道间隔还剩多少时间?
I have set a NSTimer.scheduledTimerWithTimeInterval method which has an interval every 20 minutes. I want to be able to find out how much time is left when the the app goes into background mode. How do I find out how much time is left from the interval?
谢谢
推荐答案您可以访问 NSTimer 的 fireDate,它会告诉您计时器何时将再次触发.
You have access to a NSTimer's fireDate, which tells you when the timer is going to fire again.
现在和 fireDate 之间的区别是您可以使用 NSDate 的 timeIntervalSinceDate API.
The difference between now and the fireDate is an interval you can calculate using NSDate's timeIntervalSinceDate API.
E.G.类似:
let fireDate = yourTimer.fireDate let nowDate = NSDate() let remainingTimeInterval = nowDate.timeIntervalSinceDate(fireDate)更多推荐
如何从 NSTimer 中找到剩余的时间间隔
发布评论