iosswiftuikittouches

Cancel touch events for other views


I have a UIView subclass that displays some content on top of camera preview (AR, but not ARKit). In this view I use touchesBegan and touchesEnded to detect if user has pressed on displayed objects. Now I have this view embedded in controller inside UINavigationController and this NavigationController has enabled showing/hiding bars on tap. I would like to make so that if I detect tapping on object inside ARView, then I can perform some action, but then touches are not received by NavigationController, so that bars are hiding only if I tap on background. How can I block sending touch events further in such situation?


Solution

  • so, if I understood you correctly, you want to recognize both events, and call methods of both gestures, right? If so, try this code snippet:

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
    

    This method allows to recognize several gestures