如何在UIWebView中检测onclick或ontouchend事件? 或者这甚至可能吗?
谢谢。
答案 0 :(得分:1)
子类UIWebView和实现
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//Do your code here
[super touchesBegan:touches withEvent:event];
}
修改强>
您可以拦截使用此UIWebViewDelegate方法按下的URL:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *link = url.absoluteString;
NSLog(@"Link pressed: %@", link);
return YES;
}
答案 1 :(得分:0)
尝试这种方式:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:webView];
if(CGRectContainsPoint([webView frame], currentLocation)){
//perfrom action
}
}