问题
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!
回答1:
The method -(NSUInteger)numberOfTouches of UIGestureRecognizer could tell you how many touches on it.
来源:https://stackoverflow.com/questions/8500549/how-to-determine-number-of-touches-that-are-scrolling-uitableview