美文网首页
关于WKWebView截图

关于WKWebView截图

作者: BestJoker | 来源:发表于2017-06-15 09:58 被阅读2124次

看了好多文章都没有好的办法,自己改了一个方法,达到效果,大家可以尝试.好用的请给个赞

- (UIImage*)captureView:(WKWebView *)webView
{
    UIImage* image = nil;
        //优化图片截取不清晰
    UIGraphicsBeginImageContextWithOptions(webView.scrollView.contentSize, true, [UIScreen mainScreen].scale);
    {
        CGPoint savedContentOffset = webView.scrollView.contentOffset;
        CGRect savedFrame = webView.scrollView.frame;
        webView.scrollView.contentOffset = CGPointZero;
        webView.scrollView.frame = CGRectMake(0, 0, webView.scrollView.contentSize.width, webView.scrollView.contentSize.height);
        for (UIView * subView in webView.subviews) {
            [subView drawViewHierarchyInRect:subView.bounds afterScreenUpdates:YES];
        }
        image = UIGraphicsGetImageFromCurrentImageContext();
        webView.scrollView.contentOffset = savedContentOffset;
        webView.scrollView.frame = savedFrame;
    }
    UIGraphicsEndImageContext();
    if (image != nil) {
        return image;
    }
    return nil;
}

相关文章

网友评论

      本文标题:关于WKWebView截图

      本文链接:https://www.haomeiwen.com/subject/awsyqxtx.html