Skip to main content
 首页 » 操作系统

ios之'@lvalue $T 7' is not identical to ' CGPoint!'

2024年01月01日36grandyang

我试图在 iOS 上的 SceneKit 中移动节点集合,但我遇到了一个神秘错误。到目前为止,这是我的代码:

func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) { 
    let cubes = scene.rootNode.childNodesPassingTest { (node, stop) -> Bool in node.name == "cube" } 
    for cube in cubes { 
        cube.position = SCNVector3(x: cube.position.x - 5.0, y: cube.position.y, z: cube.position.z) 
    } 
} 

在线 cube.position = ... 我得到 '@lvalue $T7' is not identical to 'CGPoint!'

这个错误是什么意思?另外,如果有更好的方法遍历这些节点,请告诉我!谢谢。

请您参考如下方法:

childNodesPassingTest returns an [AnyObject] Swift 无法弄清楚 cube 是什么类型(显然它认为 position 属性是 CGPoint!)。显式地将 cubes 转换为 [SCNNode] 应该可以解决这个问题:

for cube in cubes as [SCNNode] { 
    cube.position = SCNVector3(x: cube.position.x - 5.0, y: cube.position.y, z: cube.position.z) 
}