tags:

views:

75

answers:

1

Hi Folks,

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@" touches ");
}

The above method is not calling in my apps. My application description is as under.

I have a MainViewController which loads a ContentViewController in it. ContentViewController has a webview which loads a pdf file.

How to listen the tap of MainViewController's View.

Regards.

A: 

I may be not 100% accurate here, but if you place -touchesBegan:withEvent: in your view controller (or its main view) then you will get only those touches that have not been handled by some subviews in the view hierarchy. To intercept all touches you should use UIView subclass for your controller view and override hitTest:withEvent: method in it:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    touchedView = [super hitTest:point withEvent:event];
    NSSet* touches = [event allTouches];
    // handle touches if you need
    return touchedView;
}

For more information see Event delivery section in "Event handling guide" for iOS

Vladimir
@VladimirThanks Vladimir. Can you please give me a link about view hierarchy.Regards.
iWasRobot
Updated answer with the link to event handling explanation in Apple docs - it seems it confirms my answer
Vladimir
@VladimirI did this. Its working. But now UIWebView has stopped working.
iWasRobot
What does not work exactly? Do you return correct view from hitTest method?
Vladimir
@VladimirPlease see the link : http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects
iWasRobot