【问题标题】:Rendering a UIWebView in drawRect with loadHTMLString使用 loadHTMLString 在 drawRect 中渲染 UIWebView
【发布时间】:2011-01-28 22:57:31
【问题描述】:

我遇到了 UIWebView 的问题。我想在其中呈现我自己的 html 代码。当我将 webview 添加为子视图并放入一些 html 代码时,它呈现得很好。当它使用 drawRect 方法进行一些优化的 tableview 单元格绘图时,问题就会出现。以这种方式绘制 UIView 后代效果很好。甚至可以使用 loadRequest 方法加载 URL,设置委托,符合 UIWebViewDelegate 协议并在调用 webViewDidFinishLoad 时使用 setNeedsDisplay 重绘表格单元格。它确实显示了,但是当涉及到 loadHTMLString 时,什么都没有显示,只有一个白色的矩形。由于性能原因,我必须在 drawRect 方法中进行绘图。

有什么想法吗?提前致谢 尼克

UIWebView 正在加载的 html 代码的示例 sn-p 代码:

NSString *html = @"<html><head><title>My fancy webview</title></head><body style='background-color:green;'><p>It somehow seems<h2 style='color:black;'>this does not show up in drawRect</h2>!</p></body></html>"; 
[webView loadHTMLString:html baseURL:nil];

drawRect 方法的代码片段:

- (void)drawRect:(CGRect)aRect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    [[webView layer] renderInContext:context];
}

【问题讨论】:

  • 您可以将 Web 视图渲染到图像的图形上下文中,保留该图像并将其添加到表格视图单元格的视图层次结构中,或者根据您的需要将其绘制到 drawRect 中的图形上下文中.

标签: iphone html objective-c uiwebview drawrect


【解决方案1】:

我认为您需要在该索引处重新加载单元格,而不是调用 setNeedsDisplay。

【讨论】:

  • 宁可调用 [super drawRect:aRect]; .
猜你喜欢
  • 2013-08-10
  • 2012-09-10
  • 2011-12-12
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多