1

这是我的代码:

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request  navigationType:(UIWebViewNavigationType)navigationType;  {
/* Add Content Loading Banner */
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
    [self.view addSubview:linkLoadView];
    linkLoadView.alpha = 1.0;
}

/* Handle PDF Opening */
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
if([urlString rangeOfString:@".pdf"].location == NSNotFound){
    return true;
} else {
    NSURL *filePath = [NSURL URLWithString:urlString];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
    [pdfViewer loadRequest:requestObj];
    [self.view addSubview:topView];
    [self.view addSubview:linkLoadView];    
    return false;
}   

}

基本上,它的作用是从我的 UIWebView webView 中检测 PDF 链接并将其加载到另一个 UIWebView pdfViewer(在名为 topView 的视图上找到)。然后我有一个功能如下:

- (void) webViewDidFinishLoad:(UIWebView *)theWebView{
        //for webView
        [UIView animateWithDuration:2
                 animations:^{
                      loadingView.alpha = 0.0;
                      linkLoadView.alpha = 0.0;
                 }
                 completion:^(BOOL finished){
                     [loadingView removeFromSuperview];
                     [linkLoadView removeFromSuperview];
                 }];

}

对于 pdfViewer web 视图,上述函数根本不会触发,但对于 webView web 视图会触发。我该如何解决?

这是我在 viewDidLoad 方法上对两个 webView 的设置设置。

//Options for 
webView.delegate = self;
webView.scalesPageToFit = YES;
for (id subview in webView.subviews)
    if ([[subview class] isSubclassOfClass: [UIScrollView class]])
        ((UIScrollView *)subview).bounces = NO;

//Options for 
pdfViewer.delegate = self;
pdfViewer.scalesPageToFit = YES;
for (id subview in pdfViewer.subviews)
    if ([[subview class] isSubclassOfClass: [UIScrollView class]])
        ((UIScrollView *)subview).bounces = NO;
4

1 回答 1

1

确保 pdfViewer 委托设置正确,您可能需要调整加载代码。

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request  navigationType:(UIWebViewNavigationType)navigationType;  {
    /* Add Content Loading Banner */
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        [self.view addSubview:linkLoadView];
        linkLoadView.alpha = 1.0;
    }

    /* Handle PDF Opening */
    NSURL *url = [request URL];
    NSString *urlString = [url absoluteString];
    if(webview != pdfViewer)
    {
        if([urlString rangeOfString:@".pdf"].location == NSNotFound){
            return true;
        } 
        else {
            NSURL *filePath = [NSURL URLWithString:urlString];
            NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
            [pdfViewer loadRequest:requestObj];
            [self.view addSubview:topView];
            [self.view addSubview:linkLoadView];    
            return false;
        }
    }
    return true;
}
于 2011-04-06T13:47:16.510 回答