0

I have a complex view hierarchy with all sorts of UIGestureRecognizer's.

I then present an overlay UIView and if the user interacts with this overlay, I do not want any gesture recognizers to fire that were placed underneath that overlay. Currently, for example, dragging causes gesture recognizers to fire beneath the overlay view to fire.

I would like to avoid any solution that leads to potential spaghetti code (ex. iterating through the view hierarchy and disabling gesture recognizers).

Similar question(s):

kgaidis
  • 14,259
  • 4
  • 79
  • 93
  • Obvious question: What did you try? Please search, I'm almost sure this has been discussed/answered here multiple times. – meaning-matters Oct 18 '17 at 20:22
  • @meaning-matters Surprisingly, I could not find any reasonably clean answer for this question. As for what I tried, might be unpopular, but I purposefully left that out to not bias answers; as a result of your request, I posted a potential answer below as to not pollute the question space (again, might be unpopular, sorry!). I am just looking to see what creative answers others have, as I could not find any clean answers elsewhere. – kgaidis Oct 18 '17 at 20:30

1 Answers1

0

The only kind-of-clean solution I can think of is adding all types of gesture recognizers on the overlay view so those get fired instead of the ones beneath.

For example:

overlayView.addGestureRecognizer(UIPanGestureRecognizer(target: nil, action: nil))
overlayView.addGestureRecognizer(UILongPressGestureRecognizer(target: nil, action: nil))
overlayView.addGestureRecognizer(UISwipeGestureRecognizer(target: nil, action: nil))
kgaidis
  • 14,259
  • 4
  • 79
  • 93