绘制UIWebView图层时出现问题 [英] Problem in drawing UIWebView layer

查看:69
本文介绍了绘制UIWebView图层时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取UIWebView的图层,然后渲染它.这是我的代码:

I want to get the layer of UIWebView then I want to render it. This is my code:

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 700, 1024)];
[webView loadHTMLString:@"Display This HTML String" baseURL:nil];

CALayer *webViewLayer = [webView layer];
[webViewLayer renderInContext:ctx];

我得到的只是空白页.

All I am getting is blank page.

但是如果我使用UIView而不是UIWebView,则代码可以正常工作. 我是在做错什么,我无法注意到还是无法获得UIWebView层,或者是否有其他方法可以获取UIWebView层.

but if I take UIView instead of UIWebView then code works fine. Am I doing something wrong which I am not able to notice or cant we get the layer of UIWebView or is there any other method for getting the layer of UIWebView.

感谢.

推荐答案

UIWebView非常单一,通常不打算访问其组件.一切或多或少都被隐藏了.

The UIWebView is pretty monolithic and its components are generally not intended to be accessed. Everything is more or less hidden away.

您可以通过循环浏览Web视图的子视图来作弊",但是您可能会遇到Apple不赞成访问私有类的情况,例如:

You can "cheat" by looping though the web view's subviews, but you'll probably run into Apple's disapproval of accessing private classes, e.g.:

CALayer *webViewLayer;
for (UIView *_subview in [[[webView subviews] objectAtIndex:0] subviews]) {
    if ([_subview isKindOfClass:[UIWebDocumentView class]]) {
        webViewLayer = [_subview layer];
    }
}
[webViewLayer renderInContext:ctx];

如果您打算将其发布在App Store上,则访问私有类将导致您的应用被拒绝.

Accessing private classes will cause your app to be rejected, if you intend to publish this on the App Store.

这篇关于绘制UIWebView图层时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆