在UIScrollView中滚动时未调用touchesBegan方法

时间:2011-05-11 23:44:39

标签: iphone objective-c

我注意到如果我立即将手指放在它上面并滚动,则不会在UIScrollView中调用touchesBegan方法。 touchsBegan只有在我滚动之前将手指放置一定时间后才会被调用。不应该在UIS​​crollView上触摸时始终调用开始?

2 个答案:

答案 0 :(得分:20)

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

 -(void) hideKeyBoard:(id) sender
 {
    // Do whatever such as hiding the keyboard
 }

答案 1 :(得分:5)

我相信UIScrollView拦截这些事件,目的是弄清楚你是否要滚动包含视图。实际上,看起来它首先获得它们(这与正常处理相反,最深的子视图首先获得它们),以便它可以判断是否存在滚动或捏合手势。见How does UIScrollView steal touches from its subviews?