![](/img/trans.png)
[英]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.