Ios UIWebView.scrollview使用SnapshotViewAfterScreenUpdate的图像为白色

Ios UIWebView.scrollview使用SnapshotViewAfterScreenUpdate的图像为白色,ios,uiwebview,uiimage,Ios,Uiwebview,Uiimage,我试图截取整个webView(UIWebView)的屏幕截图,并将其存储为UIImage,以便以后检索 我的密码是: var tempView = webView.scrollView.snapshotViewAfterScreenUpdates(true) UIGraphicsBeginImageContextWithOptions(tempView.bounds.size, false, 0) webView.drawViewHierarchy

我试图截取整个webView(UIWebView)的屏幕截图,并将其存储为UIImage,以便以后检索

我的密码是:

        var tempView = webView.scrollView.snapshotViewAfterScreenUpdates(true)
        UIGraphicsBeginImageContextWithOptions(tempView.bounds.size, false, 0)
        webView.drawViewHierarchyInRect(tempView.frame, afterScreenUpdates: true)
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
当我将第一行代码替换为

        var tempView = webView.snapshotViewAfterScreenUpdates(true)
我得到了webView可见部分的屏幕截图。但我的目标是获得整个webView屏幕截图,包括不可见部分

感谢您在这方面的帮助

编辑:我已经能够使用renderInContext获得scrollview的屏幕截图。但我了解到,HierarcyRect中的drawViewInHierarcyRect比renderinContext()性能更好,我想利用这一点。我还想比较两种方法的内存使用情况


为了拍摄可视区域的屏幕截图,renderInContext创建了4个7MB临时内存块,而drawViewInHierarchy创建了2个。您是否在
webViewDidFinishLoad:
方法中调用这部分代码?我将其作为func webView的一部分调用(webView:UIWebView,shouldStartLoadWithRequest:NSURLRequest,navigationType:UIWebViewNavigationType)->Bool。因此,在我离开网页之前,我先拍摄它的屏幕截图,然后导航到新的url