我基本上有一首卡通需要跳舞的歌曲。
有没有更好:
版本 A:一首完整的歌曲并调度一堆队列:
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
//Have the figure dance move 1
}
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
//Have the figure dance move 2
}
或分段歌曲和 Action :
func dancing(){
timeElapsed += 1
if timeElapsed == 1 {
\\figure does move 1
self.playSound()
} else if timeElapsed == 2 {
\\figure does move 2
self.playSound2()
}
作为总结:
版本a:同时调度多个队列
版本 b:分割队列,但这意味着我的项目将有 10 多个媒体文件
反正有测试这个吗?或者有什么替代方法?我四处寻找并看到了并发/同步队列之类的东西,但对如何在实践中使用它们知之甚少。
最佳答案
如果不想嵌套太多,可以使用UIViewPropertyAnimator
.例如:
let animation1 = UIViewPropertyAnimator(duration: 0.5, curve: .linear) {
// animation code
}
let animation2 = UIViewPropertyAnimator(duration: 1, curve: .linear) {
// animation code
}
animation1.addCompletion { _ in
animation2.startAnimation()
}
animation1.startAnimation()
关于ios - 运行一系列短动画的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61672781/