我目前正在学习,请原谅我的无知。有没有办法在Swift中反转动画?我有一个在SCNTransaction中包含一些基本动画的函数,并且我有一个激活该动画的按钮。
func displayAnimation() {
if let displayAnimationNode = sceneView.scene.rootNode.childNode(withName: "display", recursively: true) {
SCNTransaction.begin()
displayAnimationNode.position.y = 3
displayAnimationNode.eulerAngles.z = -2
SCNTransaction.animationDuration = 2.5
SCNTransaction.commit()
}
}
我已经阅读了文档,但似乎没有.reversed方法。如何使动画同样平滑但相反?
答案 0 :(得分:1)
使用SCNAction添加反向动画。
let moveY = SCNAction.moveBy(x: 0, y: 3, z: 0, duration: 2.5)
let moveZ = SCNAction.moveBy(x: 0, y: 0, z: -2, duration: 2.5)
let moveYZ = SCNAction.sequence([moveY, moveZ])
// You can use group to simultaneously perform animation
// let rotateAndHover = SCNAction.group([moveY, moveZ])
// This line of code will reverse your animation
moveYZ.reversed()
let repeatForever = SCNAction.repeatForever(moveXZ)
runAction(repeatForever)
我希望这会对您有所帮助。