0

Is there a method to detect and log all gesture messages received by a project and/or all potential touch responders?

I am writing a new iOS 8 master/detail universal project which is experiencing a conflict between the default swipe to go back behavior and finger-based drawing. Yet, when I attempt to log the gesture behavior on the detail controller via, for example gestureRecognizerShouldBegin, the code is never called.

user216661
  • 323
  • 3
  • 14

1 Answers1

1

I solved this problem by iterating through my list of viewControllers.views to identify subview and then log each gesture recognizer - or anything else I am interested in - associated with each view. To iterate the views, if I had subclassed my views, I would have used the recursive method suggested here. Because I did not, I slightly modified the code here.

Then, I wrote utility functions for future use:

+ (NSMutableArray *)getAllSubviews:(UINavigationController *)navigationController {

    NSMutableArray *allSubviews     = [[NSMutableArray alloc] initWithObjects: nil];
    NSMutableArray *currentSubviews = [[NSMutableArray alloc] initWithObjects: nil];
    NSMutableArray *foundSubviews     = [[NSMutableArray alloc] initWithObjects: nil];

    NSLog(@"\n%lu total controllers:\n%@",navigationController.viewControllers.count, navigationController.viewControllers);

    for (UIViewController *vc in navigationController.viewControllers) {
        [currentSubviews addObject: vc.view];
        [foundSubviews addObject: vc.view];

        while (foundSubviews.count) {

            [foundSubviews removeAllObjects];

            for (UIView *view in currentSubviews) {

                for (UIView *subview in view.subviews)
                    [foundSubviews addObject:subview];
            }

            [currentSubviews removeAllObjects];
            [currentSubviews addObjectsFromArray:foundSubviews];
            [allSubviews addObjectsFromArray:foundSubviews];

        }
    }
    NSLog(@"\n%lu total subviews:\n%@",allSubviews.count, allSubviews);

    return allSubviews;
}
+ (void)logAllGestureRecognizers:(UINavigationController *)navigationController {

    NSMutableArray *allViews = [self getAllSubviews: navigationController];

    for (UIView *v in allViews) {
        for (UIGestureRecognizer *gestureRecognizer in v.gestureRecognizers) {
            NSLog(@"Gesture Recognizer  %@", gestureRecognizer);
        }
    }
}

Call the functions with [YourUtilityObject logAllGestureRecognizers:self.navigationController];

One caveat: This implementation assumes the self.navigationController is aware of all of your active view controllers. If you are creating a new navigationController for your current viewController, then the results will only display the views associated with that navigationController and you will have to manually call the function for each navigation controller.

Community
  • 1
  • 1
user216661
  • 323
  • 3
  • 14