touchesBegan method not called when scrolling in U

2020-08-19 20:57发布

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?

2条回答
迷人小祖宗
2楼-- · 2020-08-19 21:52

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?

查看更多
对你真心纯属浪费
3楼-- · 2020-08-19 21:54
 UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];
 [scrollView addGestureRecognizer:gestureRecognizer];

 -(void) hideKeyBoard:(id) sender
 {
    // Do whatever such as hiding the keyboard
 }
查看更多
登录 后发表回答