2011-04-26 66 views

回答

1

子类的UIWebView并实施

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    //Do your code here 

    [super touchesBegan:touches withEvent:event]; 
} 

编辑

可以拦截利用该UIWebViewDelegate方法按下网址:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    NSURL *url = request.URL; 
    NSString *link = url.absoluteString; 
    NSLog(@"Link pressed: %@", link); 

    return YES; 
} 
+0

我怎么知道用户按下了哪个链接? – iosdevnyc 2011-04-26 20:00:48

+0

@harekam_taj检查我的编辑答案以捕获被按下的链接。 – Cyprian 2011-04-26 20:51:24

0

试试这个方法:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
    { 

     UITouch *touch = [touches anyObject]; 

    CGPoint currentLocation = [touch locationInView:webView]; 

    if(CGRectContainsPoint([webView frame], currentLocation)){ 

//perfrom action 
} 
}