【发布时间】:2014-11-10 12:26:02
【问题描述】:
我正在尝试捕获 WKWebView 的屏幕截图,但我的方法无法正常工作,它返回纯色,就好像图层树为空一样,而它似乎适用于其他视图。
- (UIImage *)screenshot
{
UIImage *screenshot;
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenshot;
}
【问题讨论】:
-
你找到iOS的解决方案了吗?目前我正在使用 snapshotViewAfterScreenUpdates。但是我必须在呈现 webview 之后调用它,所以我在 didFinishNavigation 中等待 0.1 秒并调用 snapshotViewAfterScreenUpdates。不是很方便和可靠(
-
WKWebView 的视频录制也遇到了同样的问题。它只是一个白色方块,而 UIWebView 记录正确。看起来还没有找到决定
-
仅供参考,renderInContext 适用于 iOS 10,适用于 iOS 9 的模拟器,但不适用于配备 iOS 9 的设备。请小心测试。
-
这仍然困扰着我 2019 年的 iOS 12 - 非常不稳定的区域!
标签: ios objective-c iphone uiview wkwebview