Handle taps within a UIWebView

Submitted by:Andery Smith

Date added:28 May, 2012

Category:iPhone

iPhone code snippet to handle taps within a UIWebView

Tags: uiwebview , handle taps

Code Snippet:

//1. Add UIGestureRecognizerDelegate to your interface:
@interface DocumentViewControler : UIViewController <UIGestureRecognizerDelegate>

//2. Add to viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer* singleTap=[[UITapGestureRecognizer
alloc]initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTouchesRequired=1;
singleTap.delegate=self;
[self.webView addGestureRecognizer:singleTap];
[singleTap release];
}

//3. Add:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
*)otherGestureRecognizer {
return YES;
}

//4.
-(void) handleSingleTap:(UITapGestureRecognizer *)recognizer {
NSLog(@"handleSingleTap");
// Your code here
}
@end
 
 

Comments