NSTimer 官方文档翻译

A timer that fires after a certain time interval has elapsed, 
sending a specified message to a target object.

在某个特定时间间隔过后触发的定时器,向目标对象发送置顶的消息。

Timers work in conjunction with run loops. Run loops maintain strong references to their timers, 
so you don’t have to maintain your own strong reference to a timer after you have added it to a run loop.

计时器与RunLoop 联合工作。RunLoop持有对他们的计时器的强引用,所以不用在计时器加入到RunLoop之后,保持对计时器的强引用。

A timer is not a real-time mechanism. If a timer’s firing time occurs during a long run loop callout or while the run loop is in a mode that isn't monitoring the timer, the timer doesn't fire until the next time the run loop checks the timer. 
Therefore, the actual time at which a timer fires can be significantly later. See also Timer Tolerance.

一个定时器并不是实时机制。如果一个定时器的触发事件发生在一个很长的RunLoop或者此RunLoop处于没有监控此定时器的模式下,那么计时器直到下次RunLoop循环检查到该定时器的时候才会被触发。因此,定时器触发的会比真实时间明显延迟。详见定时器公差。

Comparing Repeating and Nonrepeating Timers
You specify whether a timer is repeating or nonrepeating at creation time. A nonrepeating timer fires once and then invalidates itself automatically, thereby preventing the timer from firing again. By contrast, a repeating timer fires and then reschedules itself on the same run loop. A repeating timer always schedules itself based on the scheduled firing time, as opposed to the actual firing time. For example, if a timer is scheduled to fire at a particular time and every 5 seconds after that, the scheduled firing time will always fall on the original 5-second time intervals, even if the actual firing time gets delayed. If the firing time is delayed so far that it passes one or more of the scheduled firing times, the timer is fired only once for that time period; the timer is then rescheduled, after firing, for the next scheduled firing time in the future.

对比重复定时器与非重复定时器

在创建之初,你可以区分定时器是重复的还是非重复的。
一个非重复的定时器值触发一次,然后就自动失效了。从而组织定时器再次触发。
相反,一个重复的定时器触发,然后在同一个RunLoop(运行循环)中重新安排自己。
一个重复的定时器经常基于预定的触发事件触发自身,而不是实际的触发时间。
比如,一个定时器被安排在特定的时间被触发,并且每五秒钟触发一次,那么即使真实的触发时间被延迟了,计划的触发时间也会执行原始的5秒间隔。当触发事件延迟超过了一个或者多个预定的触发时间是,该时间段就会只触发一次。在触发之后,定时器会被重新安排,以遍等待在下一个触发时间点的到来。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值