UIWebView 打开 PDF 时 webViewDidFinishLoad 未触发
这是我的代码:
- (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;
Here is my code:
- (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;
}
}
Basically what this does is detect a PDF link from within my UIWebView webView and loads it into an additional UIWebView pdfViewer (found on a View called topView). I then have a function as below:
- (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];
}];
}
The above function doesn't fire at all for the pdfViewer web view, but does for the webView web view. How do I fix this?
Here is my setup settings for both webViews, on the viewDidLoad method.
//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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保 pdfViewer 委托设置正确,您可能需要调整加载代码。
Make sure that the pdfViewer delegate is set properly and you will probably need to adjust the loading code.