1

I've been looking for a way to intercept all touch events of an app. I saw that I can add a gesture recognizer to the main window and get all the touches by using it's delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog(@"%@",touch);
return NO;
}

This way I don't harm all of the other touch events the app has. The problem is that I cannot get swipe events and such this way. Moreover, I cannot override UIWindow sendEvents because my app is an outside framework. I also do not want to add a transparent UIView on top.

Is there any other way to get swipes and other gesturs?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Adam
  • 51
  • 7

2 Answers2

0

To intercept all touch events of an app, use a UIWindow subclass and override sendEvent:.... Every touch event passes through this bottleneck method. Be warned that you are now operating at a very low level and can easily break everything.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

I managed to get this to work by using a custom gesture recognizer attached to the keyWindow and with using the method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

Which also gives me all the touches and doesn't disturb any other recognizers.

If anyone know why I shouldn't be doing that, I'd be happy to hear about it.

Adam
  • 51
  • 7