简体   繁体   English

时间戳与CADisplayLink的1/60

[英]timestamp vs 1/60 for CADisplayLink

I am currently using CADisplayLink to perform some specific deceleration animation. 我目前正在使用CADisplayLink执行一些特定的减速动画。 I set the frameInterval to 1. I have seen some open source projects just use 1/60 second as time delta between frame updates. 我将frameInterval设置为1。我已经看到一些开源项目在帧更新之间仅使用1/60秒作为时间增量。 I found there is also a timestamp method available, however it is in mach format. 我发现还有一种时间戳方法可用,但是它是马赫格式。 Which one should I use, can I assume all the iPhone refresh rate is 60hz, and hence safe to use 1/60? 我应该使用哪一个,我可以假设所有iPhone的刷新率均为60hz,因此可以安全使用1/60? If I use timestamp method, how should I convert it to seconds? 如果使用时间戳方法,应如何将其转换为秒?

Many thanks in advance. 提前谢谢了。

Using 1/60 s as time delta is dangerous because you never know if future devices or external displays will use that refresh rate. 使用1/60 s作为时间增量很危险,因为您不知道将来的设备或外部显示器是否会使用该刷新率。 So if you want to be future-proof, you should rather use a timestamp-based solution. 因此,如果您想适应未来的发展,则应该使用基于时间戳的解决方案。 You can use the Unix epoch timestamp and compute the interval between 2 target calls: 您可以使用Unix时代时间戳记并计算两次目标调用之间的间隔:

UInt64(NSDate().timeIntervalSince1970 * 1000.0)

You can also use the CADisplayLink timestamp, which is already in seconds: https://developer.apple.com/reference/quartzcore/cadisplaylink/1621257-timestamp 您还可以使用已经以秒为单位的CADisplayLink时间戳: https : //developer.apple.com/reference/quartzcore/cadisplaylink/1621257-timestamp

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

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