11

I noticed touchesBegan method is not called in UIScrollView if i immediately place my finger on it and scroll. touchesBegan only gets called after i place my finger for a certain time duration before scrolling. Shouldn't touchesBegan always be called whenever there is a touch on the UIScrollView?

prostock
  • 9,327
  • 19
  • 70
  • 118

2 Answers2

21
 UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];
 [scrollView addGestureRecognizer:gestureRecognizer];

 -(void) hideKeyBoard:(id) sender
 {
    // Do whatever such as hiding the keyboard
 }
Shady Abdou
  • 241
  • 2
  • 6
5

I believe that UIScrollView intercepts these events, for the purpose of figuring out if you are going to be scrolling the containing view. Actually, it looks like it gets them first (which is opposite normal processing, where the deepest subview gets them first) so that it can figure out if there is a scroll or pinch gesture. See How does UIScrollView steal touches from its subviews?

Community
  • 1
  • 1
David Neiss
  • 8,161
  • 2
  • 20
  • 21
  • thx, i read that post. do u think UIScrollView overrides its pointInside:withEvent: so that UIScrollView's touchesBegan doesn't get called? – prostock May 12 '11 at 00:28
  • I havent tried it, but I figured it was something like overriding - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event to get the touch events routed to it, then do the detection, and if not detected, then do what that function used to do as a container view. – David Neiss May 12 '11 at 00:39