UIWebView - remove the download indicator, BEFORE the images are finished loading, but AFTER the WebView is rendered

I know that you can implement loading UIViewusing regular UIWebViewdelegation methods webViewDidStartLoad:andwebViewDidFinishLoad:

However, this approach means that you have to wait until ALL the images .gifare fully loaded before deleting the boot view. Since UIWebViewby default it loads asynchronously (lazily) the images on the page, I would like to remove the loading view when rendering the page, but it is not necessary to wait for all images to load.

I did not find any resources in this, but I am sure that this was done as a rather important optimization. Any ideas?

+4
source share
1 answer

With these questions, you can use JavaScript to change the location of the UIWebView window immediately after the DOM has finished loading (e.g. jQuery):

$(document).ready(function(){
    location.href = http://removeLoadingScreen
})

Then use the UIWebView delegate method to select this link and remove the loading screen:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;

    if([[url absoluteString] isEqualToString:@"http://removeLoadingScreen"]){
        // remove loading screen
    }
}

Images and .gif are not yet loaded, but the rest of the page will be. The only drawback is that the space for images may be blocked or not yet blocked, so the text content may jump down the page after the images appear.

+1
source

Source: https://habr.com/ru/post/1525979/


All Articles