简体   繁体   English

如何为屏幕上显示的图像获取准确的持续时间计时器?

[英]How can I get an accurate duration timer for an image that is displayed on the screen?

I am trying to get an accurate time interval for an image that is displayed on the screen for only a short duration. 我正在尝试为仅在短时间内显示在屏幕上的图像获取准确的时间间隔。

Let's say that I want an image to be displayed for around 150ms on the screen, I know that most iOS devices have a variable refresh rate (usually between 20-60Hz) so this will mean that it is impossible to hit that 150ms perfectly on the mark. 假设我希望图像在屏幕上显示约150ms,我知道大多数iOS设备具有可变的刷新率(通常在20-60Hz之间),因此这意味着不可能在屏幕上完美地达到150ms标记。 What I would like to know, is there a way to measure the exact time interval for the image being displayed? 我想知道的是,有没有一种方法可以测量所显示图像的确切时间间隔? Ideally, I'd like for this to be accurate to within a few milliseconds. 理想情况下,我希望此精度在几毫秒内。

Thanks in advance for any help I can get! 在此先感谢您能获得的任何帮助!

If you use Metal, you can add a "presented handler" block to be called when the drawable has been presented (shown on screen). 如果使用Metal,则可以添加一个“呈现的处理程序”块,以在呈现可绘制对象时显示(在屏幕上显示)。 Use the -addPresentedHandler: method of MTLDrawable to do that. 使用-addPresentedHandler:方法MTLDrawable做到这一点。 In that block, you can query the presentedTime property of the drawable. 在该块中,您可以查询drawable的presentedTime属性。

If you use that to first show an image and then clear the image (display black or white or whatever), then you can compare the two presented time values to determine how long the image was displayed. 如果使用它先显示图像然后清除图像(显示黑色或白色或其他内容),则可以比较两个显示的时间值以确定显示图像的时间。

In addition to that, you can schedule presentation of a drawable for a specific time, using the -presentDrawable:atTime: (or, depending on your needs, -presentDrawable:afterMinimumDuration: ) method of MTLCommandBuffer . 除此之外,您还可以使用-presentDrawable:atTime:或根据您的需要, -presentDrawable:afterMinimumDuration:方法在特定时间安排可绘制对象的MTLCommandBuffer

You should look at using a CADisplayLink . 您应该看看使用CADisplayLink It's a timer that's synced to the screen refresh cycle. 它是一个与屏幕刷新周期同步的计时器。

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

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