I'm trying to implement a type of "Help mode" on my iOS app. When the user taps the help button, touches to the screen are intercepted by a UITapGestureRecognizer and if it is on a control, a little popup appears with help info.
My problem however is that the application only detects that I have tapped a control if I tap in the upper half of the control. I use hitTest:withEvent: to determine which view was touched:
CGPoint touchPoint = [(UITapGestureRecognizer*)sender locationInView:nil];
UIView* touchedView = [self.view hitTest:touchPoint withEvent:nil];
UILabels are especially hard to hit successfully.
The View contains a navigationbar at the top but is fairly standard. Has anyone had a similar issue? Does anyone know of a solution?
You need to get the location of the touch in your view, not in the window (which is what you get when you specify nil
as the view).
CGPoint touchPoint = [(UITapGestureRecognizer*)sender locationInView:self.view];
UIView* touchedView = [self.view hitTest:touchPoint withEvent:nil];