第一次火灾后延迟计时器 [英] Delay timer after first fire
问题描述
我的应用程序中有一个触发特定事件的计时器:
I have a timer in my application that triggers a certain event:
myTimer = NSTimer.scheduledTimerWithTimeInterval(10, target: self,
selector: "searchForDrivers:", userInfo:nil, repeats: true)
首次触发计时器时,其延迟为10毫秒.我不希望第一个计时器触发延迟,但我希望第二个触发延迟10毫秒.我该如何实现?
The first time the timer is triggered, it has a delay of 10 ms. I don’t want the delay on the first timer trigger, but I'd like the second trigger to be delayed by 10 ms. How can I achieve this?
推荐答案
首先按照您的计划安排计时器.
First schedule the timer as you've done.
timer = NSTimer.scheduledTimerWithTimeInterval(
10.0, target: self,
selector: "searchForDrivers:",
userInfo: nil,
repeats: true
)
然后立即射击timer
.
timer.fire()
根据文档
您可以使用此方法来触发重复计时器,而不会中断其常规触发时间表.如果该计时器是非重复计时器,则即使触发时间未到,它也会在触发后自动失效.
You can use this method to fire a repeating timer without interrupting its regular firing schedule. If the timer is non-repeating, it is automatically invalidated after firing, even if its scheduled fire date has not arrived.
请参见 NSTimer类参考以获取更多信息.
See the NSTimer Class Reference for more information.
这篇关于第一次火灾后延迟计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!