I am having an issue with trying to customize my gesture responder chain
I come from Cocoa/macOS & Mouse Events, and the concept of gestures has been tripping me up
Assumptions based on my research:
Instead of mouse events being passed to
NSResponders
, There are Tap, Press, and Gesture events. Tap and Press get passed toUIResponders
, Gestures are passed toGestureRecognizers
(owned by aUIView
)The difference between touchBegan/touchMoved/touchEnded and a Gesture recognizer depends on the speed of the finger? (uigesturerecognizers-vs-touchesbegan-touchesmoved-touchesended-accuracy). So if you tap, and slowly move, the underlying UIView receives the
touchMoved
events. If you Tap and drag quickly, a gesture is created and passed to the the GestureRecognizer of the underlyingUIView
. I am pretty uncertain on this one, so I am opening another SO question to address this issueWhen I say "swipe left", I mean the opposite direction your finger goes, and I mean left as in the direction of the navigation animation. same with "swipe right".
I have a problem with my "Gestures" not being sent to the Gesture Recognizers I would like. (I originally thought that gestures went to the controllers, but I have since learned that isn't the case, and GestureRecognizers are owned by the Views)
View Hierarchy:
- "Swipeable" UITabBarController (SwipeableTabBarController)
- UIViewController
- UIViewController
- UIViewController (UIView)
- PageViewController (_PageContentView and _UIQueueingScrollView)
- CollectionViewController (CollectionView)
- PageViewController (_PageContentView and _UIQueueingScrollView)
So here's what I am trying to make happen:
- If you swipe anywhere on the screen, you will move between the 3
UIViewControllers
(ThanksSwipeableTabBarController
) - If you swipe right on the third right-most
UIViewController
, you will actually flip through the pages of thePageViewController
) - If you swipe left on the third
UIViewController
(which holds thePageViewController
), and you are in the left-most page of thePageViewController
, you will go left into the second (middle)UIViewController
However,
Once you navigate to the right-most
UIViewController
, all swipe gestures are consumed by theUIQueueingScrollView
on theUIPageViewController
. This means that Once you are in the right-most view, you cannot swipe back left to the middle view. Swiping just flips between pages, (and in the case of being on the left page, nothing happens)I have manually enumerated over subviews to find this
UIQueueingScrollView
, and removed allGestureRecognizers
from it, and this allows the gestures to get passed up to theSwipeableTabBarController
, so that you can swipe back to the middle view... But this of course breaks theUIPageViewController
's scrolling
My Goal:
Somehow mutate the GestureRecognizers in the UIPageViewController
(it looks like I have to do it on it's _UIQueueingScrollView
), so that
if you are looking at the left-most page:
- do a swipe left gesture:
- will be passed to the GestureRecognizers in
SwipeableTabBarController
. Main UIViewControllers will swap
- will be passed to the GestureRecognizers in
- do a swipe right gesture:
- will be passed to the
GestureRecognizers
inUIQueueingScrollView
, and the pageview will flip to the next page
- will be passed to the
- do a swipe left gesture:
else if you are looking at any other page:
- all swipe gestures passed to the
UIQueueingScrollView
- all swipe gestures passed to the
My biggest hangup is that I can't just override gesture receivers, I have to create new custom GestureRecognizers and manually attach them to my views... but then I don't know how to have these new custom GestureRecognizers pass the gestures up the view hierarchy