我无法捕获WKWebView的屏幕截图 [英] I can't capture the screenshot of a WKWebView
本文介绍了我无法捕获WKWebView的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试捕获WKWebView的屏幕截图但是我的方法无法正常工作,它返回一个纯色,好像图层树是空的,而它似乎适用于其他视图。
I'm trying to capture a screenshot of a WKWebView but my method doesn't work properly, it returns a solid color as if the layer tree was empty, while it seems to work on other views.
- (UIImage *)screenshot
{
UIImage *screenshot;
UIGraphicsBeginImageContext(self.frame.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenshot;
}
推荐答案
这Stackoverflow答案在iOS 8上使用WKWebView解决了这个问题,其中 [查看snapshotViewAfterScreenUpdates:]
和 [view.layer renderInContext:]
返回纯黑色或白色:
This Stackoverflow answer solved it for me on iOS 8 with a WKWebView where [view snapshotViewAfterScreenUpdates:]
and [view.layer renderInContext:]
either returned solid black or white:
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage* uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这篇关于我无法捕获WKWebView的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文