title: Forwarding UIGesture to views behind
body: <p>I am working on an iphone (iOS 4.0 or later) app and having some troubles with touch handling between multiple views. I am having a view structure like this</p>
  
  <pre><code>---&gt; A superView 
       |
       ---&gt; SubView - A 
       |
       ---&gt; SubView - B (exactly on top of A, completely blocking A).
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/zBkpS.png" alt="enter image description here"></p>
  
  <p>Basically I have a superView, and sibling subviews A and B. B has the same frame as A, hence hiding A completely. </p>
  
  <p>Now my requirement is this. </p>
  
  <ol>
  <li><strong>SubView B should receive all swipe and tap (single and double)
  gestures.</strong></li>
  <li><strong>SubView A should receive all pinch gestures.</strong></li>
  </ol>
  
  <p>This is how I added gesture recognizers to the views</p>
  
  <pre><code>UISwipeGestureRecognizer *leftSwipe  =  [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe:)];
  [leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
  leftSwipe.delegate  =   self;
  [bView addGestureRecognizer:leftSwipe];
  [leftSwipe release];
  
  UISwipeGestureRecognizer *rightSwipe  =  [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe:)];
  [rightSwipe setDirection:(UISwipeGestureRecognizerDirectionRight)];
  rightSwipe.delegate   =   self;
  [bView addGestureRecognizer:rightSwipe];
  [rightSwipe release];
  
  UIPinchGestureRecognizer *pinch   =  [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
  pinch.delegate    =   self;
  [aView addGestureRecognizer:pinch];
  [pinch release];
  </code></pre>
  
  <p>I did some research and to me <code>UIGestureRecognizerDelegate</code> looked promising and I implemented the delegate method</p>
  
  <pre><code>- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  </code></pre>
  
  <p>I returned NO for SubView B, hoping that underlying view will get these event. No such luck though</p>
  
  <pre><code>- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
      if ([gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] &amp;&amp; [gestureRecognizer view] == bView) {
          NSLog(@"pinchGesture");
          //bView.userInteractionEnabled = NO;
          return NO;
      }
      return YES;
  }
  </code></pre>
  
  <p>Then I disabled user interaction of SubView B inside the delegate callback (commented code in above block), when pinch gesture is recognized, hoping remaining part of gesture will be received by SubView A. No such luck there too.. </p>
  
  <p>So that is where I stand now. I have seen <a href="https://stackoverflow.com/questions/6175255/uigesturerecognizer-receive-touch-but-forward-it-to-uicontrol-as-well">this</a> question, where the accepted answer involves property <code>cancelsTouchesInView</code>. But I believe <code>cancelsTouchesInView</code> only cancel a particular touch event, do not forward it. </p>
  
  <p>Any other way to achieve my requirement? I am ready to work on whatever hint you provide.</p>
  
  <h2>EDIT : BOUNTY TIME</h2>
  
  <p>My so called subView A is actually an instance of a 3rd party library's View class, which takes all touches away and I don't have any control over any gestures on it. I want different implementation for left and right swipe and I want pinch, tap etc work just like it is working with this third party view. So I put a view on top of A (SubView B) to get left and right swipes. But now I want to forward other gesture events to underlying library.</p>