简体   繁体   English

如何将TimeInterval设置为每秒512?

[英]How to set TimeInterval to 512 per second?

I am working on graph using opengl, I want to set timer for 512 values per second I did like this: 我正在使用opengl进行图形处理,我想将计时器设置为每秒512个值,我这样做是:

self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/512.0 
                               target:self
                               selector:@selector(drawView) 
                               userInfo:nil 
                               repeats:YES];

In draw method, I have plotted graph but it is not printing 512 values per second. 在绘制方法中,我已经绘制了图形,但是每秒不打印512个值。

Can any one please help me, whether it is right or wrong? 不管是对是错,任何人都可以帮助我吗?

An NSTimer probably just can't fire that fast. NSTimer可能无法快速启动。

A timer is not a real-time mechanism; 计时器不是实时机制。 it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer's firing time has passed. 仅当添加了计时器的运行循环模式之一正在运行并且能够检查计时器的触发时间是否经过时,它才会触发。 Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. 由于典型的运行循环会管理各种输入源,因此计时器时间间隔的有效分辨率限制在50到100毫秒的数量级。

http://developer.apple.com/library/ios/#documentation/cocoa/reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html http://developer.apple.com/library/ios/#documentation/cocoa/reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

Which gives you 10-20 ticks a second, unless you're doing something really special. 除非您正在做一些特别的事情,否则您每秒可以得到10-20个滴答声。

That's just not going to work. 那只是行不通的。

There are (at least) two reasons. 有(至少)两个原因。

  1. " Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds ." 由于典型的运行循环管理着各种输入源,因此计时器时间间隔的有效分辨率被限制在50-100毫秒的数量级 。” So you can't expect to have more than around ten timers fire per second. 因此,您不能期望每秒触发大约十个以上的计时器。
  2. Not sure what the maximum framerate on iOS is, but there's probably not much point in going much above 60. 不确定iOS上的最大帧速率是多少,但是将其提高到60以上可能没有多大意义。
[NSTimer scheduledTimerWithTimeInterval:1.0f/512.0f target:self selector:@selector(drawView) userInfo:nil repeats:YES];

try to use this one 尝试使用这个

let me know whether it is working or not!!! 让我知道它是否有效!!!

Happy Coding!!!! 编码愉快!!!

I am able to plot 512 values per second.. same timeinterval i used but i refer Accelerometer graph: http://developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Listings/MainViewController_m.html#//apple_ref/doc/uid/DTS40007410-MainViewController_m-DontLinkElementID_10 I customized it according to my requirement and it working as i fine. 我能够每秒绘制512个值..我使用相同的时间间隔,但是我参考了加速度计图: http : //developer.apple.com/library/ios/#samplecode/AccelerometerGraph/Listings/MainViewController_m.html#//apple_ref/ doc / uid / DTS40007410-MainViewController_m-DontLinkElementID_10我根据自己的要求对其进行了自定义,并且可以正常工作。 Thanks!!! 谢谢!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM