如何确定滚动 UITableView 的触摸次数
当调用 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
时,我试图确定 UITableView 上的手指触摸次数 &相应地执行某些任务。
到目前为止我尝试过的两种方法是:
- 子类化 UITableView 以覆盖
touchesBegan:withEvent:
- 这种方法的问题在于,只有当屏幕上有“一些”点击时,才会触发此方法,而不是当用户只是快速滚动而不休息手指时。 - 使用
uipangesturerecognizer
检测触摸次数。 - 我按以下方式使用它:
UIPanGestureRecognizer *taps = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
taps.maximumNumberOfTouches=4;
taps.minimumNumberOfTouches=1;
[self.tableView addGestureRecognizer:taps];
然后
-(void)handleTap:(UITapGestureRecognizer *)sender{
if (sender.state == UIGestureRecognizerStateBegan) {
NSLog(@"BEGAN - %d",sender.numberOfTouches);
}
}
虽然我能够用这种方法获得触摸次数,但问题是它覆盖了实际滚动(正常滚动没有发生)。
请指出我哪里错了或者还应该做什么。 谢谢!
I am trying to determine number of finger touches on UITableView when - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
is called & perform some task accordingly.
Two approaches that I have tried so far are:
- Subclassing UITableView to override
touchesBegan:withEvent:
-
The problem with this approach is that this method is only fired when there is 'some' tap on the screen, not when the user just quickly scrolls without resting the finger. - Using
uipangesturerecognizer
to detect number of touches. -
I am using it in the following way:
UIPanGestureRecognizer *taps = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
taps.maximumNumberOfTouches=4;
taps.minimumNumberOfTouches=1;
[self.tableView addGestureRecognizer:taps];
And then
-(void)handleTap:(UITapGestureRecognizer *)sender{
if (sender.state == UIGestureRecognizerStateBegan) {
NSLog(@"BEGAN - %d",sender.numberOfTouches);
}
}
Although I am able to get the number of touches with this approach, but the problem is that it is overriding actual scrolling (normal scrolling is not happening).
Please suggest where I am wrong or what else shall be done.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIGestureRecognizer 的方法 -(NSUInteger)numberOfTouches 可以告诉你有多少次触摸。
The method -(NSUInteger)numberOfTouches of UIGestureRecognizer could tell you how many touches on it.