gpt4 book ai didi

ios - 自定义事件指示器的基于计时器的动画的更好替代方案?

转载 作者:行者123 更新时间:2023-11-28 06:43:32 25 4
gpt4 key购买 nike

我有一个显示自定义不确定进度指示器的类。每个计时器更新它只是使用 CGAffineTransformRotate 增加 UIImageView 的旋转。

这一切都有效,但是,我注意到当它运行时,它正在等待的后台进程运行速度慢了 50%——这是一个巨大的损失。例如;而不是花 20 秒来完成处理,它需要 30 秒。有人可以推荐性能损失较小的解决方案吗?

func show() {
timer?.invalidate()
timer = NSTimer.scheduledTimerWithTimeInterval(0.03, target: self, selector: #selector(self.updateTimer(_:)), userInfo: nil, repeats: true)
}

func updateTimer(sender: NSTimer) {
iconView.transform = CGAffineTransformRotate(iconView.transform, 0.15)
}

最佳答案

使用 Core Animation 为旋转设置动画。窗口服务器将在您的应用进程之外完成所有工作。

let animation = CABasicAnimation(keyPath: "transform.rotation")
animation.fromValue = 0
animation.toValue = 2 * M_PI
animation.repeatCount = .infinity
animation.duration = 1.25
iconView.layer.addAnimation(animation, forKey: animation.keyPath)

关于ios - 自定义事件指示器的基于计时器的动画的更好替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37222871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com