title: IOS/Objective-C: Detect Textfield touch but Exclude tap of underlying scrollview
body: <p>I have a <code>UIViewController</code> containing a <code>UIScrollView</code> that takes up the whole VC and within the <code>UIScrollView</code> various elements including a number of text fields. </p>
  
  <p>I have a generic method for dismissing the keyboard where if you tap anywhere on the scrollview, the keyboard is dismissed as follows:</p>
  
  <pre><code>in viewdidload:
  
  UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self 
  action:@selector(tapped)];
      tapScroll.cancelsTouchesInView = NO;
      tapScroll.delegate = self;
      [self.scrollView addGestureRecognizer:tapScroll];
  
  - (void) tapped
  {
  NSLog(@"tapped on scrollview");
      [self.view endEditing:YES];
  }
  </code></pre>
  
  <p>The problem is that when you click on <code>UITextField</code>, a fair percentage of the time it triggers the tapped method because the click on the textfield also registers as tap on underlying scrollview. This keeps the keyboard from appearing so you can't enter anything into the keyboard.  (I can prevent this behaviour by commenting out <code>[self.view endEditing:YES];</code> in the tapped method).</p>
  
  <p>Can anyone suggest a way to detect the textfield touches to show keyboard without causing scrollview to recognize tap, or alternatively dismiss keyboard only on touching blank part of the screen.</p>
  
  <p>Thanks for any suggestions.</p>