Search code examples
iosobjective-cgestureuipangesturerecognizerpan

Fake Pan Gesture in Code


I'm trying to fake pan gesture, but am not sure how to do it. There is some complicated code determining what happens with the pan gesture, so before going in and abstracting out all the logic, I was wondering if anybody knew of a way to fake the gesture. Thanks.


Solution

  • Unfortunately the API does not provide a way to trigger the gesture programmatically nor does it provide public access to the targets and selectors of the UIGestureRecognizer.

    However, if you are wanting to do this for unit tests, you could get access to the targets and selectors by doing the following:

    NSArray *targets = [panGesture valueForKey:@"_targets"];
    NSArray *actions = [panGesture valueForKey:@"_actions"];
    

    You can then loop through those arrays and call the action on the target:

    [target performSelector:selector withObject:panGesture];