【问题标题】:WKWebView drawViewHierarchyInRect doesn't render webGL content on phoneWKWebView drawViewHierarchyInRect 不在手机上呈现 webGL 内容
【发布时间】:2017-01-08 19:16:08
【问题描述】:

我的应用有一个 WKWebView,它显示一个包含一些 webGL 内容的网页。在网页加载后,我使用 drawViewHierarchyInRect 将 WKWebView 呈现为图像。这在模拟器上运行良好,但在手机上,webGL 内容不会呈现到图像上。网页的其余部分呈现正常。在电话上,drawViewHierarchyInRect 调用返回 false(文档说“如果快照缺少层次结构中任何视图的图像数据,则返回 false”)。

这是我正在使用的代码:

UIGraphicsBeginImageContextWithOptions(webView.bounds.size, true, 0.0)

let drewOK = webView.drawViewHierarchyInRect(webView.bounds, afterScreenUpdates: true)

if (!drewOK)
{
    print("drawViewHierarchyInRect failed") // when the web page contains webGL this is printed on a phone but not in simulator
}

let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

photoPreview.image = overlayImage

iOS 9 和 iOS 10 都会出现此问题。

我还需要做些什么才能让它在手机上运行吗?

一个演示项目可用on GitHub

【问题讨论】:

  • 也没有找到解决方案。 takeSnapshotWithConfiguration:completionHandler: 也不捕获 webgl 内容。

标签: ios webgl wkwebview


【解决方案1】:

是的,我也遇到了这个问题。我尝试了很多方法,但无法解决。 唯一的方法可能是这样的:设置WebGLRenderer的'preserveDrawingBuffer'为真,调用canvas''toDataURL'做快照,然后发送到app,最后保存。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 2016-06-04
    相关资源
    最近更新 更多