假设我可能有一个UIWebView显示一个包含link. 当用户单击链接时,是否可以触发事件来更新 native UI?例如,当用户单击链接时,我想更改UIProgressView. 有没有办法做到这一点?谢谢!
			
			3539 次
		
3 回答
            2        
        
		
尝试使用此方法:
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
   return TRUE;
}
您可以检查 navigationType 值:
enum {
   UIWebViewNavigationTypeLinkClicked,
   UIWebViewNavigationTypeFormSubmitted,
   UIWebViewNavigationTypeBackForward,
   UIWebViewNavigationTypeReload,
   UIWebViewNavigationTypeFormResubmitted,
   UIWebViewNavigationTypeOther
};
    于 2013-07-02T06:44:51.780   回答
    
    
            0        
        
		
您需要实现 webView:shouldStartLoadWithRequest:navigationType: 协议方法。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    // the request variable contains the request the user clicked on.
}
    于 2013-07-02T06:41:59.047   回答
    
    
            0        
        
		
您可以通过下面的委托方法在 UIWebview 中使用检测触摸事件
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    NSLog(@"Touches began");
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
   NSLog(@"Touches moved");
}
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    NSLog(@"Touches ended");
}
- (void) touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
    NSLog(@"Touches cancelled");
}
您必须添加覆盖主视图的 UIWebView 并添加扩展 UIWindow 以捕获触摸事件的自定义类。
您可以在此处找到分步教程博客。
于 2013-07-02T06:46:59.600   回答