SCNPlane 的高度没有动画

SCNPlane's height not animating

我正在使用此代码为飞机的高度设置动画。

func animPlane2(){
            let animSize = CABasicAnimation(keyPath: "height")
            animSize.duration = 1.5
            animSize.byValue = 40
            animSize.repeatCount = Float.infinity
            animSize.autoreverses = true
            planeNode.addAnimation(animSize, forKey: nil)
        }

调试器抛出: [SCNKit 错误] 高度不是动画路径(来自 | 否 child>)

关于飞机高度的文档指出:

The extent of the plane along its vertical axis. Animatable.

这是一个错误还是我做错了什么?

看起来您正在尝试在节点而不是几何体上添加动画。

SCNNode 没有名为 height 的 属性。这是您指定为节点几何体的 SCNPlane 的 属性,因此这是您需要向其添加动画的部分:

planeNode.geometry?.addAnimation(animSize, forKey: nil)

或者,您可以将动画添加到节点,但设置其 keyPath 以影响几何体的高度:

let animSize = CABasicAnimation(keyPath: "geometry.height")
// ...
planeNode.addAnimation(animSize, forKey: nil)