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 
} 
}