这是我的代码:
- (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;
答案 0 :(得分: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;
}