1

如何检测scenekit中是否触摸了SCNBox?我正在构建一个 VR 应用程序

4

1 回答 1

0

你可以使用这个:

let tapGR = UITapGestureRecognizer(target: self, action: #selector(tapGesture(sender:)))
sceneView.addGestureRecognizer(tapGR)

@objc func tapGesture(sender: UITapGestureRecognizer) {

    let location: CGPoint = (sender.location(in: self.sceneView))
    let hits = self.sceneView.hitTest(location, options: nil)
    if let tappedNode : SCNNode = hits.first?.node {
        tappedNode.position.y += 0.5
        print(tappedNode)
    }
}
于 2019-12-13T10:30:57.527 回答