How do I tell when a UIWebView is done rendering (not loading)?

后端 未结 6 1979
失恋的感觉
失恋的感觉 2020-12-13 18:07

I know when its done loading... (webViewDidFinishLoad), but I want to use

[webView.layer renderInContext:UIGraphicsGetCurrentContext()];

to

6条回答
  •  囚心锁ツ
    2020-12-13 18:50


    What about using the window.onload or jQuerys $(document).ready event to trigger the shouldStartLoad callback?

    Something like:

    $(document).ready(function(){
        location.href = "app://do.something"
    })
    

    and in your UIWebViewDelegate do something like:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        NSURL *url = request.URL;
    
        if([url.host isEqualToString:@"app"]){
            //maybe check for "do.something"
            //at this point you know, when the DOM is finished
        }
    }
    

    With this method you can forward every possible event from the JS code to your obj-c code.

    Hope that helps. The code sample is written in the browser, and therefore not tested! ;-)

提交回复
热议问题