1

Background: I need to look at every UITouch that happens in an application and see if the UITouch is NOT inside a certain UIImageView.

WildcardGestureRecognizer looked very promising and I tried it. (Code is here): How to intercept touches events on a MKMapView or UIWebView objects?

It worked great for a sandbox/quickly-created application. However that application didn't reflect the complexity that the actual target project has. The target project has a Table View Controller and more.

After adding the WildcardGestureRecognizer to the more involved iPad application, I see that none of the other controls work after the gesture recognizer is added and one click happens.

Here's some code where I was playing with the idea. Again, the sandbox code does not yet have controls on it (such as a Table View Controller or even a UIButton) to see if they work after adding the gesture recognizer to the UIWindow.

Should I pick something other than the UIWindow to add the gesture recognizer to or am I going to run into the same problem regardless? Is there a better way?

sandbox code: https://github.com/finneycanhelp/GestureKata

Community
  • 1
  • 1
finneycanhelp
  • 9,018
  • 12
  • 53
  • 77

1 Answers1

2

You might want to try another approach: create a UIWindow subclass, use that in your XIB and override hitTest:withEvent:. It returns the view that has been "selected" to receive the touch events.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *v;

    v = [super hitTest:point withEvent:event];
    if (v == myImageView) {
        // Do something. Maybe return nil to prevent the touch from getting
        // sent to the image view.
    }

    return v;
}

Overriding this method can also be helpful when debugging.

DarkDust
  • 90,870
  • 19
  • 190
  • 224