首页 > 解决方案 > 使用完成处理程序在 Swift 中调用连续动画

问题描述

我正在制作一个显示化学反应动画的应用程序。每个原子都是一个 SCNSphere,并使用 SCNActions 进行动画处理。我正在尝试使用 runAction() 中的完成处理程序在当前动作完成后调用下一个动画,因为每个原子必须进行很多不同的动作。

这只是我为简化过程而编写的一些测试代码,实际代码将循环遍历atom对象数组。

func animate() {
    let atom1 = atomNodes[0]
    atom1.runAction(atoms[0].actions[0]) {
        atom1.runAction(SCNAction.move(by: SCNVector3(-10, 0, 0), duration: 1.0))
        print("Done")
    }
}

print("Done")语句工作正常,仅在操作完成后才调用它,但新的 SCNAction 不会触发。我是否错过了一些让下一个动作开始的东西?

标签: swiftanimationscenekithandlercompletion

解决方案


我最终去了

Timer.scheduledTimer(timeInterval: stepDuration, target: self,
                     selector: #selector(self.animate), userInfo: nil, repeats: true)

类似于 James P 的评论。


推荐阅读