在iOS10版本中,建议使用preferredFramesPerSecond属性来代替frameInterval属性。preferredFramesPerSecond属性是一个只读属性,用于指定每秒钟的最佳帧速率。可以使用CADisplayLink类来根据preferredFramesPerSecond属性来更新动画。例如:

let displayLink = CADisplayLink(target: self, selector: #selector(updateAnimation))
displayLink.preferredFramesPerSecond = 60
displayLink.add(to: .current, forMode: .defaultRunLoopMode)

@objc func updateAnimation() {
    // Update animation
}

在updateAnimation方法中,可以更新动画的状态,使其与每秒钟的帧速率同步。注意,preferredFramesPerSecond属性仅仅是一个建议值,实际的帧速率可能会略微不同。


原文地址: https://www.cveoy.top/t/topic/bRNj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录