I want to track all user touches within a designated UIViewController subclass, e.g. MyViewController.
As this UIViewController may contain UIKit-Elements, such as UIButtons, etc. I thought of lying a clear touch tracking UIView above the other views in MyViewController's view.
Now I get touch events sent to the UIView, but I don't know how to delegate the touches to the other subviews.
I already tried iterating over all MyViewController's view subviews (except the touch tracking UIView) and sending them touchesBegan:withEvent:, touchesMoved:withEvent:, etc.
But this does not work for UICollectionViews.
What I basically need is tracking all touch events in MyViewController's view frame. MyViewController itself could inherit various other views that need to respond to touch events.
I also found here (http://stackoverflow.com/questions/8423174/detecting-all-touches-in-an-app) the idea to subclass UIWindow and to override sendEvent: This would be possible in my case, but then I would have to enable/disable touch tracking whether MyViewController is visible or not. Also I don't know yet how to differentiate between touchesBegan:withEvent, touchesMoved:withEvent:, etc.
Thanks in advance.
Cheers, tubtub
in MyViewController.m
- (void)loadView
{
[super loadView];
VETouchTrackingView *touchTrackingView;
touchTrackingView = [[VETouchTrackingView alloc] initWithFrame:self.view.frame];
touchTrackingView.userInteractionEnabled = YES;
self.touchTrackingView = touchTrackingView;
[self.view addSubview:self.touchTrackingView];
[self.view bringSubviewToFront:self.touchTrackingView];
}
I managed to get the touch tracking I need by overriding sendEvent: in my UIWindow subclass.
This works pretty nice.
Here is the github project for anyone who also needs this: https://github.com/bhr/BHTouchTracking