如何检测是否在scenekit中触摸了SCNBox?

时间:2016-07-28 17:48:11

标签: ios scenekit scnnode scnvector3

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

1 个答案:

答案 0 :(得分: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)
    }
}