<small id='FC5h4'></small><noframes id='FC5h4'>

      <i id='FC5h4'><tr id='FC5h4'><dt id='FC5h4'><q id='FC5h4'><span id='FC5h4'><b id='FC5h4'><form id='FC5h4'><ins id='FC5h4'></ins><ul id='FC5h4'></ul><sub id='FC5h4'></sub></form><legend id='FC5h4'></legend><bdo id='FC5h4'><pre id='FC5h4'><center id='FC5h4'></center></pre></bdo></b><th id='FC5h4'></th></span></q></dt></tr></i><div id='FC5h4'><tfoot id='FC5h4'></tfoot><dl id='FC5h4'><fieldset id='FC5h4'></fieldset></dl></div>

      <tfoot id='FC5h4'></tfoot>
      <legend id='FC5h4'><style id='FC5h4'><dir id='FC5h4'><q id='FC5h4'></q></dir></style></legend>

        <bdo id='FC5h4'></bdo><ul id='FC5h4'></ul>

      1. 通过在后台线程上渲染 UIWebView 创建 UIImage - iPhone

        时间:2023-10-22

        <legend id='w0V8t'><style id='w0V8t'><dir id='w0V8t'><q id='w0V8t'></q></dir></style></legend>

      2. <i id='w0V8t'><tr id='w0V8t'><dt id='w0V8t'><q id='w0V8t'><span id='w0V8t'><b id='w0V8t'><form id='w0V8t'><ins id='w0V8t'></ins><ul id='w0V8t'></ul><sub id='w0V8t'></sub></form><legend id='w0V8t'></legend><bdo id='w0V8t'><pre id='w0V8t'><center id='w0V8t'></center></pre></bdo></b><th id='w0V8t'></th></span></q></dt></tr></i><div id='w0V8t'><tfoot id='w0V8t'></tfoot><dl id='w0V8t'><fieldset id='w0V8t'></fieldset></dl></div>

              <tbody id='w0V8t'></tbody>
          • <small id='w0V8t'></small><noframes id='w0V8t'>

            <tfoot id='w0V8t'></tfoot>

                  <bdo id='w0V8t'></bdo><ul id='w0V8t'></ul>

                  本文介绍了通过在后台线程上渲染 UIWebView 创建 UIImage - iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否有人知道一种方法,或者有关于如何获取从 UIWebView 呈现的 UIImage 的创意?关键是,它必须在后台线程上.

                  Does someone know of a way, or has a creative idea as to how to obtain an UIImage that is rendered from a UIWebView? The catch is, that is must be on a background thread.

                  我会详细说明:我试图每秒从多个 UIWebViews 获取图像+-,并将其显示在屏幕上(当然是 iPhone).因为将图层渲染到 CGContext 是一项消耗 CPU 的工作,所以我不想使用主线程,所以不要挂起 UI.

                  I'll elaborate: I'm trying to obtain the image from multiple UIWebViews every second+-, and display it on screen (iPhone's of course). Because rendering a layer to a CGContext is a CPU consuming job, I wouldn't like to use the main thread, so not to hang the UI.

                  到目前为止,我的尝试是:

                  My attempts so far were:

                  • 我尝试在 webView 的层上使用 renderInContextUIGraphicalContext,但是 _WebTryThreadLock 错误导致 webview 崩溃.

                  • I tried to use renderInContext on the webView's layer to the UIGraphicalContext, but the _WebTryThreadLock error crashed the webviews.

                  我尝试创建一个 CGBitmapContext,并将 webview 的图层渲染到它,但得到了相同的结果.

                  I tried creating a CGBitmapContext, and render the webview's layer to it, but got the same result.

                  我尝试实现一个 copy 方法(通过添加一个类别)到 CALayer,该方法深度复制了所有公共属性和子层.之后,我尝试 renderInContext 我复制的图层.我得到了一个部分正确"的 UIImage - 意思是,并非所有图层都被渲染,所以例如,我只会得到网站页眉(或页脚,或正文,或搜索栏,或只是一些框架).UIWebview 的层由各种子类 CALayers 组成,所以这可能就是这种方法不起作用的原因.

                  I tried implementing a copy method (by adding a Category) to CALayer, that deep copied all of the public properties, and sublayers. Afterwards, I tried to renderInContext the layer I copied. I got a UIImage that was partially "correct" - meaning, not all of the layers were rendered, so for example, i would get only the website header (or footer, or body, or search bar, or just a some of the frames). The UIWebview's layer consists of all sort of subclassed CALayers, so this is probably why this approached didn't work.

                  我尝试在 CATransaction 中设置 kCATransactionDisableActions,但似乎并没有改变这种行为(两者都没有).

                  I tried setting the kCATransactionDisableActions in a CATransaction, but it didn't appear to change this behavior (neither of them).

                  我已经快要放弃了.

                  你们中间有救世主吗?

                  推荐答案

                  UIWebView 讨厌,我的意思是 真的讨厌,在后台线程上对其进行任何处理.UIKit 不是完全线程安全的.绘制到图形上下文是(这是在 iOS 4 中添加的),但不是在辅助线程上创建 UIView.

                  UIWebView hates, and I mean really hates, having anything done to it on a background thread. UIKit is not fully thread safe. Drawing to a graphics context is (this was added in iOS 4), but not creating UIViews on a secondary thread.

                  你是在主线程之外创建你的 UIWebViews 吗?你也许有一些代码要分享?我怀疑您的问题是由于您尝试在辅助线程上对 UIWebView 执行操作这一事实引起的.将视图内容呈现为图像的绘图操作可以在主线程之外进行,但创建视图本身不能.

                  Are you creating your UIWebViews off the main thread? Do you perhaps have some code to share? I would suspect your issues are being caused by the fact you're trying to perform operations to a UIWebView on a secondary thread. The drawing operation to render the view's contents as an image can happen off the main thread, but creating the view itself can't.

                  这篇关于通过在后台线程上渲染 UIWebView 创建 UIImage - iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么在创建 UIWebView 后清除 NSUserDefaults 会导致 EXC_CRASH? 下一篇:当 scalesPageToFit 为 ON 时 UIWebView 禁用缩放

                  相关文章

                  <tfoot id='OadXh'></tfoot>
                • <small id='OadXh'></small><noframes id='OadXh'>

                    <legend id='OadXh'><style id='OadXh'><dir id='OadXh'><q id='OadXh'></q></dir></style></legend>

                      <bdo id='OadXh'></bdo><ul id='OadXh'></ul>

                    <i id='OadXh'><tr id='OadXh'><dt id='OadXh'><q id='OadXh'><span id='OadXh'><b id='OadXh'><form id='OadXh'><ins id='OadXh'></ins><ul id='OadXh'></ul><sub id='OadXh'></sub></form><legend id='OadXh'></legend><bdo id='OadXh'><pre id='OadXh'><center id='OadXh'></center></pre></bdo></b><th id='OadXh'></th></span></q></dt></tr></i><div id='OadXh'><tfoot id='OadXh'></tfoot><dl id='OadXh'><fieldset id='OadXh'></fieldset></dl></div>