Iphone – Handling touches inside UIWebview

iphoneuiwebview

I have created a subclass of UIWebView , and have implemented the
touchesBegan, touchesMoved and touchesEnded methods.

but the webview subclass is not handling the touch events.

Is there any method to handle the touch events inside the UIWebView subclass ???

Best Answer

No subclassing needed, just add a UITapGestureRecognizer :

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMethod)];
[tap setNumberOfTapsRequired:1]; // Set your own number here
[tap setDelegate:self]; // Add the <UIGestureRecognizerDelegate> protocol

[self.myWebView addGestureRecognizer:tap];

Add the <UIGestureRecognizerDelegate> protocol in the header file, and add this method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
Related Topic