Hi,
I have the following situation: One view covering the whole screen, several subviews all over the place.
In the view controller (which controls the large root view) I've implemented several gesture recognizers, like this:
Code:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSingleTap:)];
[singleTap setNumberOfTapsRequired:1];
[singleTap setNumberOfTouchesRequired:1];
[[self view] addGestureRecognizer:singleTap];
[singleTap release];
I then have implemented the selector method in the view controller like this:
Code:
- (void)didSingleTap:(UITapGestureRecognizer*)gestureRecognizer {
}
This works all fine. What I need to do though: In didSingleTap I have to find out if the tap has occurred on top of one of the subviews. I know I can get the location of the touch with locationInView:, but this just gives me a coordinate. I need to get the actual UIView object on which the touch has occurred, so that I can manipulate the object that has been touched.
Before I have used gesture recognizers, I manually implemented touchesBegan:WithEvent: etc. in the root view, which worked fine and which actually gives me a UITouch object that contains a reference to the object on which the tap has occurred. But this means I have to manually implement the view, which I don't need and want (if possible).
One thing I thought of was to actually implement the gesture recognizers in each subview and use the root view controller as their action target. Would this work?