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

后端 未结 6 1996
失恋的感觉
失恋的感觉 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:58

    If you have access to the HTML file and can edit it - then just add some special variable which will tell the code that rendering is done.
    Then use method stringByEvaluatingJavaScriptFromString to know should you start some actions or not.
    The example below is pretty dirty, but hope it will help and give you the idea:

    (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        BOOL renderingDone = NO;
        while (!(renderingDone == [[webView stringByEvaluatingJavaScriptFromString:@"yourjavascriptvariable"] isEqualToString:@"YES"]))
        {
            // the app will be "freezed" till the moment when your javascript variable will not get "YES" value 
        }
        // do your stuff, rendering is done 
    }
    

提交回复
热议问题