Does swipeGesture block the execution of touchesBegan()?

my problem is that touchesBegan() is not called as I know it from other projects. Therefore there must be a difference somewhere to my other projects. Now I got the idea, that the following code prevents calling touchesBegan():


In didMove():


tapRec.addTarget(self, action:#selector(GameScene.tappedView(_:) ))
     tapRec.numberOfTouchesRequired = 1
     tapRec.numberOfTapsRequired = 1
     self.view!.addGestureRecognizer(tapRec)


The function:


@objc func tappedView(_ sender:UITapGestureRecognizer) {
     
     let point:CGPoint = sender.location(in: self.view)
     
     print("single tap")

     print(point)
}


touchesBegan()


override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
     for touch in touches {
     
          let locationUser = touch.location(in: self)

          if self.atPoint(locationUser) == background {
               print("background touch")
          }
     }
}

I come to the idea that the above function tappedView() is to blame for not executing touchesBegan(), since this function is called when the screen is touched instead of touchesBegan().


Is there a way to use both touchesBegan() and tappedView() without them blocking each other?


Thank you in advance.

Replies

Yes, they are conflicting.


You will find detailed explanation and a solution (disable gesture when needed) here


https://stackoverflow.com/questions/41190170/tap-gesture-to-not-occur-when-touching-a-specific-location-spritekit