ios – Swift double tap and single tap gestures both register


I am making a 3d globe in SceneKit and I want to manually detect single and double taps. Currently both functions work correctly when a gesture takes place. However the normal tap gesture is executed when the screen is double tapped. How can I avoid this?

   public override func viewDidLoad() {
       super.viewDidLoad()
       
       setupScene()
       setupCamera()
       setupGlobe()
       
       let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
       viewModel.sceneView.addGestureRecognizer(tapGesture)
   }
   
   private func setupScene() {
       let scene = SCNScene()
       viewModel.sceneView = SCNView(frame: view.frame)
   
       viewModel.sceneView.scene = scene
       viewModel.sceneView.isUserInteractionEnabled = true
       
       let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap(_:)))
       doubleTapGesture.numberOfTapsRequired = 2
       viewModel.sceneView.addGestureRecognizer(doubleTapGesture)

       self.view.addSubview(viewModel.sceneView)
   }
   
   @objc func handleTap(_ gesture: UITapGestureRecognizer) {
       let touchLocation = gesture.location(in: viewModel.sceneView)
       let hitTestResults = viewModel.sceneView.hitTest(touchLocation, options: nil)
           
       if hitTestResults.count >= 2 {

       }
   }
   
   @objc private func handleDoubleTap(_ gestureRecognizer: UITapGestureRecognizer) {
       
   }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img