I load a pdf file of size >5MB in my UIWebView
. I want to scale the PDF file to certain level after loading.
func webViewDidFinishLoad(webView: UIWebView) {
webView.scrollView.setZoomScale(3.0, animated: false)
webView.scrollView.contentOffset = CGPointMake(0, -(self.webView.scrollView.contentInset.top))
}
The above snippet gives the expected result on iOS 9+. But on iOS 8, when webViewDidFinishLoad
is fired, the pdf is not being loaded and there is no effect.
I also tried
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
webView.scrollView.setZoomScale(3.0, animated: false)
webView.scrollView.contentOffset = CGPointMake(0, -(self.webView.scrollView.contentInset.top))
}
It works fine, but not every time. Increasing the time is not a good idea, because, sometimes webView
takes more than 5 seconds to load the file.
I tried many solutions that I got on googling
UIWebView: when did a page really finish loading?
How to detect when a UIWebView has completely finished loading?
UIWebView - How to identify the "last" webViewDidFinishLoad message?
But nothing solved my problem.
The activity indicator that we see in the screenshot is not added by me. The indicator disappears after loading the PDF completely. Anyhow if we could identify the event when indicator disappears, there I can scale the file.
Is there any way to identify it? Or any other way to identify the completion of file loading?