title: Passing through touches to UIViews underneath
body: <p>I have a <code>UIView</code> with 4 buttons on it and another <code>UIView</code> on top of the buttons view.  The top most view contains a <code>UIImageView</code> with a <code>UITapGestureRecognizer</code> on it.</p>
  
  <p>The behavoir I am trying to create is that when the user taps the <code>UIImageView</code> it toggles between being small in the bottom right hand corner of the screen and animating to become larger.  When it is large I want the buttons on the bottom view to be disabled and when it is small and in the bottom right hand corner I want the touches to be passed through to the buttons and for them to work as normal.  I am almost there but I cannot get the touches to pass through to the buttons unless I disable the <code>UserInteractions</code> of the top view.</p>
  
  <p>I have this in my <code>initWithFrame:</code> of the top view:</p>
  
  <pre><code>// Add a gesture recognizer to the image view
  UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
  tapGestureRecognizer.cancelsTouchesInView = NO;
  [imageView addGestureRecognizer:tapGestureRecognizer];
  [tapGestureRecognizer release];
  </code></pre>
  
  <p>and I this is my <code>imageTapped:</code> method:</p>
  
  <pre><code>- (void) imageTapped:(UITapGestureRecognizer *) gestureRecognizer {
      // Toggle between expanding and contracting the image
      if (expanded) {
          [self contractAnimated:YES];
          expanded = NO;
          gestureRecognizer.cancelsTouchesInView = NO;
          self.userInteractionEnabled = NO;
          self.exclusiveTouch = NO;
      }
      else {
          [self expandAnimated:YES];
          expanded = YES;
          gestureRecognizer.cancelsTouchesInView = NO;
          self.userInteractionEnabled = YES;
          self.exclusiveTouch = YES;
      }
  }
  </code></pre>
  
  <p>With the above code, when the image is large the buttons are inactive, when I touch the image it shrinks and the buttons become active.  However, the small image doesn't receive the touches and therefore wont expand.</p>
  
  <p>If I set <code>self.userInteractionEnabled = YES</code> in both cases, then the image expands and contracts when touched but the buttons never receive touches and act as though disabled.</p>
  
  <p>Is there away to get the image to expand and contract when touched but for the buttons underneath to only receive touches if the image is in its contracted state?  Am I doing something stupid here and missing something obvious?</p>
  
  <p>I am going absolutely mad trying to get this to work so any help would be appreciated,</p>
  
  <p>Dave</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>For further testing I overrode the <code>touchesBegan:</code> and <code>touchesCancelled:</code> methods and called their super implementations on my view containing the UIImageView.  With the code above, the <code>touchesCancelled:</code> is never called and the <code>touchesBegan:</code> is always called.</p>
  
  <p>So it would appear that the view is getting the touches, they are just not passed to the view underneath.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Is this because of the way the responder chain works?  My view hierarchy looks like this:</p>
  
  <pre><code>VC - View1
       -View2
        -imageView1 (has tapGestureRecogniser)
        -imageView2
       -View3
        -button1
        -button2
  </code></pre>
  
  <p>I think the OS first does a hitTest as says View2 is in front so should get all the touches and these are never passed on to View3 unless userInteractions is set to NO for View2, in which case the imageView1 is also prevented from receiving touches.  Is this how it works and is there a way for View2 to pass through it's touches to View3?</p>