如何在 iphone 应用程序中以纳秒为单位设置 NSTimer 时间间隔

编程入门 行业动态 更新时间:2024-10-28 00:21:19
本文介绍了如何在 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 毫秒.

The number of seconds between firings of the timer. If interval is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.

这意味着但没有明确定义最小值为 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 时间间隔

本文发布于:2023-10-08 13:47:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   中以   应用程序   单位   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!