I want to trigger a UIPanGestureRecognizer attached to a UIView subclass when the initial position of the touch is outside of the view (A below) of the UIView subclass. I have the following situation:
/-------------------/
| B |
| /---/ |
| | A | |
| /---/ |
| C |
| |
/-------------------/
A is the UIView that has the Pan gesture recognizer attached to it, B is the superview of A, and C is the initial position of the touch. The touch is then moved into A, and now I want A to take over the handling of the touch and the Pan recognizer to recognize the gesture and trigger its callback function.
As I understand B is returned by the initial hitTest:ing and thus will trigger the touchesBegan/Moved/Ended/Changed: handling of the touch.
How can I make the gesture recognizer of A “take over” the touch handling of this touch? Or at least receive the touches so that it may recognize the pan gesture?
My goal is to make this work when I track several touches at the same time in the situation when there are several subviews like A around, so that the touch may be “handed over” to anyone of these.
Any ideas on how to solve this would be greatly appreciated!
This might not be as “clean” as what you are looking for, but the best way that I can think of to do what you want is to add the gesture recognizer to superview “B”, and then have “B” loop over its subviews to see when the gesture is inside a particular subview and then send messages to that subview to perform the desired action.