title: How to reliably find correct view for UIGestureRecognizer?
body: <p>I have a bunch of UIViews like in the image below. The red/pink (semi-transparent) view is on top of the others.</p>
  
  <ul>
  <li>Red has a <code>UISwipeGestureRecognizer</code>. </li>
  <li>Green has as a <code>UITapGestureRecognizer</code>.</li>
  <li>Blue has no recognizer.</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/DhmiT.png" alt="enter image description here"></p>
  
  <p>A tap on the <em>visible</em> (bottom-left) part of Green trigger its recognizer.</p>
  
  <p>A tap on the <em>hidden</em> parts of Green <strong>does not</strong> trigger its recognizer (Red blocks it). </p>
  
  <p>That's the problem: I want Green to trigger. How can I do this?</p>
  
  <p>In practice, the views may be in any order, any number and be subviews of each others etc. But the problem is the same: </p>
  
  <p><strong>How can I reliably find the uppermost view that can handle the gesture (tap or swipe)?</strong></p>
  
  <hr>
  
  <p>I tried with the code below. It neatly traverses all views, but it fails since it cannot know if the event is part of a swipe or a tap. So the method always returns the red view. If I remove the swipe-recognizer from Red, the code works correctly.</p>
  
  <pre><code>- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event 
  {
      UIView *hitView = [super hitTest:point withEvent:event];
      if (hitView == self)
      {
          if (self.hasASwipeRecognizer)
              return self;  // What if this was a tap?
          if (self.hasATapRecognizer)
              return self; 
          else
              return nil;
      }
      else
           return hitView;
   }
  </code></pre>