我在iOS应用中有一个View,其中添加了多个wkwebview作为子视图来呈现html内容。它显示了所有内容,但是当我尝试拍摄屏幕截图时,它显示为空白,好像内容永远不会在wkwebviews中呈现。
代码我以前拍摄截图:
//view is parent view which contains wkwebviews as childviews
func takeScreenShot(view: UIView) -> UIImage{
UIGraphicsBeginImageContext(view.bounds.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
当我检查UI层次结构时,wkwebviews的内容实际上超出了父视图的范围。是否有正确的截屏方式?
答案 0 :(得分:0)
你试过这个:
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage* uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
取自here