【问题标题】:Taking screenshot of a view with multiple subviews as wkwebview将具有多个子视图的视图截图为 wkwebview
【发布时间】:2016-04-12 11:37:05
【问题描述】:

我在 iOS 应用程序中有一个视图,其中添加了多个 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 Hierarchy 时,wkwebviews 的内容实际上超出了父视图的范围。有合适的截图方法吗?

【问题讨论】:

    标签: ios swift uiview wkwebview


    【解决方案1】:

    你试过了吗:

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

    取自here

    【讨论】:

    • 我试过这些代码行。它冻结了 UI。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多