Damian Dudycz
Damian Dudycz

Reputation: 2810

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?

Upvotes: 0

Views: 1090

Answers (2)

Mohamad Sheikh
Mohamad Sheikh

Reputation: 283

If you desire to limit touches on different views, you can change the property of userInteractionEnabledon each condition you like.

When this property is set to false, no touch events will be received for selected views.

Upvotes: 1

Bliss
Bliss

Reputation: 575

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

Upvotes: 1

Related Questions