title: Tap Gesture Recognizer attached with container view does not block touch event of button in container view but blocks toolbar button's touch event
body: <p>So I have a view controller which has a container view. The container view is embedded with a navigation controller which is also parent controller of a view controller. The storyboard is like this: </p>
  
  <p>view controller(<code>mainViewController</code>) --> navigation controller --> view controller(<code>contentViewController</code>)</p>
  
  <p>You can see screenshot of storyboard in the below.</p>
  
  <p>The first arrow is a embed segue from container view to navigation controller. The second arrow is a relationship represents <code>contentViewController</code> is root view controller of the navigation controller.</p>
  
  <p><code>mainViewController</code> and <code>contentViewController</code> are objects of the same class, named <code>testViewController</code>. It is the subclass of UIViewController. Its implementation is simple. It only has three <code>IBAction</code> methods, nothing else. Here is the implementation code:</p>
  
  <pre><code>#import "TestViewController.h"
  
  @implementation TestViewController
  
  - (IBAction)buttonTapped:(id)sender {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                      message:@"button is tapped"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
      [alert show];
  }
  
  - (IBAction)barButtonTapped:(id)sender
  {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                      message:@"bar button is tapped"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
      [alert show];
  }
  
  - (IBAction)viewTapped:(id)sender {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                      message:@"view is tapped"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles: nil];
      [alert show];
  }        
  @end
  </code></pre>
  
  <p>I added a Tap Gesture Recognizer to the container view in <code>mainViewController</code>. It sends <code>viewTapped:(id)sender</code> message to <code>mainViewController</code> when the container view is tapped. Inside of the root view of <code>contentViewController</code>, there is a button which sends <code>buttonTapped:(id)sender</code> message to <code>contentViewController</code> when tapped. And there is a bar button in the toolbar of <code>contentViewController</code> which sends <code>barButtonTapped:(id)sender</code> message to <code>contentViewController</code> when tapped. The initial scene is <code>mainViewController</code>. When the app is running, I found that only touch events of the bar button is blocked, touch event is handled correctly by the button. In Apple's documentation, <a href="https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html#//apple_ref/doc/uid/TP40009541-CH2-SW40" rel="nofollow noreferrer">Regulating the Delivery of Touches to Views</a>, it says:</p>
  
  <blockquote>
    <p>In the simple case, when a touch occurs, the touch object is passed
    from the UIApplication object to the UIWindow object. Then, the window
    first sends touches to any gesture recognizers attached the view where
    the touches occurred (or to that view’s superviews), before it passes
    the touch to the view object itself.</p>
  </blockquote>
  
  <p>I thought touch event will not pass to the button. This really confused me. Can someone explain this behavior? Thank you very much.</p>
  
  <hr>
  
  <p><strong>Screenshot of the storyboard</strong>:
  <img src="https://i.stack.imgur.com/BZRaU.png" alt="the storyboard"></p>