简体   繁体   中英

How to determine number of touches that are scrolling UITableView

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:

  1. 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.
  2. 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!

UIGestureRecognizer的-(NSUInteger)numberOfTouches方法可以告诉您对其进行了多少次触摸。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM