Objective-c – touchesBegan not responding

objective c

-(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.

Best Answer

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

Related Topic