5
votes

I have a scenario where I have two UITableViews as a subview in a main UIView:

UIView (frame = full screen)
+--- UITableView (frame = ~1/3 of the screen)
+--- UITableView (frame = second ~1/3 of the screen)

I want to detect a three finger swipe up on the whole screen area (and also allow the user to pan UITableViews up and down with at least one finger).

I have a UISwipeGestureRecognizer attached to UIView with numberOfTouchesRequired = 3.

I've tried these:

  • Setting both internal UIPanGestureRecognizers maximumNumberOfTouches to 1 on both UITableViews. To my understanding this should prevent two and three finger pans on the UITableViews but it doesn't. (If I set enabled to NO on these UIPanGestureRecognizers, the touches are correctly passed to the superview. But then the panning/scrolling doesn't work.)
  • Calling panGestureRecognizer requireGestureRecognizerToFail: with my UISwipeGestureRecognizer on both UITableViews. This works partly, but the panning waits until the swipe hasn't been completed and it feels very clumsy.
  • Overriding UITableView with setting shouldRecognizeSimultaneouslyWithGestureRecognizer: to return YES, which allows me to detect the three finger swipe. However, the UITableViews beneath pan/scroll up unintentionally.

So how do I limit the number of panning touches to 1 (or 2) and let the three-finger UISwipeGestureRecognizer recognize three finger swipes?

1

1 Answers

0
votes

Try overriding canPreventGestureRecognizer: on the top (whole screen) UIPanGestureRecognizer, returning NO for each of the two table view gesture recognizers.

I'd also try overriding canBePreventedByGestureRecognizer: on each of the two table view gesture recognizers to return NO in the case of the topmost UIPanGestureRecognizer.

I've run into a similar situation as yourself quite a while ago and can't remember how I fixed it (the project is long gone), but I seem to remember playing around with the aforementioned methods and eventually getting it to work.