本文介绍了如何在 iphone 应用程序中以纳秒为单位设置 NSTimer 时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个一秒后调用方法的应用.

I am making an app calling methods after one second.

[NSTimer scheduledTimerWithTimeInterval:1.0
                                 target:self
                               selector:@selector(loadNews)
                               userInfo:nil
                                repeats:NO];

如何称呼这个

推荐答案

您的问题不完整.但是使用标题,我可以说您不能将 NSTimer 设置为纳秒之类的任何内容,并期望请求以您希望的方式得到尊重.

Your question is incomplete. However using the title, I can say that you cannot set the NSTimer to anything like nano-seconds and expect the request be honored in the way you hope.

它出现的最小间隔是 0.1 毫秒(或 0.0001 秒).api 文档 指出:

The smallest interval that it appears it can be set to is 0.1 milliseconds (or 0.0001 seconds). The the api documentation states:

计时器两次触发之间的秒数.如果间隔小于或等于 0.0,则此方法选择非负值 0.1 毫秒.

这意味着但没有明确定义最小值为 0.1 毫秒.

Which implies but does not definitely define the smallest value to be 0.1ms.

您应该注意,与许多计算机操作系统计时器一样 - 这是最短时间而不是最长时间 - 如果系统忙于做其他事情,不能保证它不会持续更长时间.与 Windows、MacOS 或 Linux 类似的 iOS 并不是一个实时操作系统",其设计的目的是事件的时间线对应用程序的成功至关重要.

You should note that like with many computer operating system timers - this is a minimum time not a maximum - there is no guarantee that it will not go for longer if the system is busy doing something else. iOS like Windows or MacOS or Linux is not a 'real time operating system' designed where timelines of events is paramount to the success of the application.

尝试将计时器设置为 1 纳秒级别或 0.000000001 秒是行不通的.

Trying to set a timer to 1 nano second level, or 0.000000001 seconds is just not going to work.

这篇关于如何在 iphone 应用程序中以纳秒为单位设置 NSTimer 时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:24
查看更多