Scenekit detecting User tapped object

后端 未结 3 680
遥遥无期
遥遥无期 2021-01-15 02:53

I recently started using scenekit for scenekit in iOS 8. I am facing difficulty in detecting whether the user has tapped or pressed on the object. Is there any way to do tha

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 03:26

    Add a tap gesture to the object and check whether it is a SCNNode()

         @objc func tapGestureRec(sender: UIPanGestureRecognizer? = nil){
                let location: CGPoint = (sender?.location(in: self.view))!
                let hits = self.sceneKitView.hitTest(location, options: nil)
                if let tappedNode : SCNNode = hits.first?.node {
                    ...
                }
         }
    

提交回复
热议问题