Skip to content

Instantly share code, notes, and snippets.

@xandrucea
Last active December 19, 2015 21:29
Show Gist options
  • Save xandrucea/6020199 to your computer and use it in GitHub Desktop.
Save xandrucea/6020199 to your computer and use it in GitHub Desktop.
Check tap on UIWebView
----------------------
1. add UIGestureRecognizer to declaration (h.file)
2. create TapGestureRecognizer and add to webview
UITapGestureRecognizer *webViewTapped = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(showIntersticial)];
webViewTapped.numberOfTapsRequired = 1;
webViewTapped.delegate = self;
[_webView addGestureRecognizer:webViewTapped];
3. override delegate method
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
4. write method to handle actions when tapped
- (void)showIntersticial{
// do something when had been tapped
}
check if specific element had been clicked
------------------------------------------
UITouch *touch = touches.anyObject;
CGPoint point = [touch locationInView:self.view];
// check if selected element on screen is board
UIView *hitView = [self.canvasView hitTest:point withEvent:event];
if(hitView == _canvasView){
// my element
} else {
// not my element
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment