【发布时间】: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 内容。