使用完成处理程序在Swift中调用连续动画 [英] Calling consecutive animations in Swift with completion handler

查看:104
本文介绍了使用完成处理程序在Swift中调用连续动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making an app that will show animations of chemical reactions. Each atom is an SCNSphere and is animated with SCNActions. I'm trying to use the completion handler in runAction() to call the next animation after the current action is finished since there will be a lot of different movements each atom has to make.

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

This is just some test code I wrote to simplify the process, the actual code will be looping through an array of atom objects.

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不会触发.我是否缺少一些使下一个动作开始的东西?

The print("Done") statement works just fine, it's only called once the action has finished, but the new SCNAction doesn't trigger. Am I missing something to make the next action start?

推荐答案

我最终选择了

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

类似于James P的评论.

similar to James P's comment.

这篇关于使用完成处理程序在Swift中调用连续动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆