To find a 3D node pointed to by the user in SceneKit, add a tap gesture recogniser in ViewDidLoad()
let fingerTap = UITapGestureRecognizer(target: self, action: "handleTap:")
self.view.addGestureRecognizer(fingerTap)
And here’s a simple handler:
func handleTap(sender: UIGestureRecognizer)
{
let p = sender.locationInView(self.sceneView)
let hitResults = self.sceneView.hitTest(p, options: nil)
if let results = hitResults {
if (results.count > 0) {
let result: SCNHitTestResult = results[0] as! SCNHitTestResult
println("Hit \(result)")
}
}
}