swift - 使用完成处理程序在 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 不会触发。我是否错过了一些让下一个动作开始的东西?
解决方案
我最终去了
Timer.scheduledTimer(timeInterval: stepDuration, target: self,
selector: #selector(self.animate), userInfo: nil, repeats: true)
类似于 James P 的评论。
推荐阅读
- spring-boot - Spring Boot:在长时间运行的存储过程中检测到明显的连接泄漏
- javascript - Apexchart 在条形图上添加渐变颜色不如预期
- reactjs - 使用 Apollo 获取 XML restapi 返回意外的令牌
- python - PDB 不会在多线程代码中的断点处停止
- powerbi - 如何在 Power BI 中旋转标签?
- python - 我对 wxpython 中的面板有疑问
- c# - 从 C# 调用 ARM 模板
- algorithm - 如果您有一个拓扑有序图,基于到根的最大距离的稳定排序会保留拓扑顺序吗?
- r - dplyr“加权和”和cross()
- flutter - Flutter如何重新加载整个页面