将具有多个子视图的视图的屏幕截图作为wkwebview

时间:2016-04-12 11:37:05

标签: ios swift uiview wkwebview

我在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的内容实际上超出了父视图的范围。是否有正确的截屏方式?

1 个答案:

答案 0 :(得分:0)

你试过这个:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage* uiImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

取自here