Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

touchesBegan method not called when scrolling in UIScrollView

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?

like image 605
prostock Avatar asked May 11 '11 23:05

prostock


2 Answers

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

 -(void) hideKeyBoard:(id) sender
 {
    // Do whatever such as hiding the keyboard
 }
like image 155
Shady Abdou Avatar answered Nov 15 '22 00:11

Shady Abdou


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?

like image 5
DavidN Avatar answered Nov 15 '22 01:11

DavidN