[英]Is the a way to have a timing function work on multiple animations in Swift?
[英]Is there a way to reverse animations in Swift?
我目前正在学习,所以请原谅我的无知。 有没有办法在 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 方法。 我怎样才能让这个动画同样流畅但相反?
使用 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)
我希望这能帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.