NSOperation 和 UIKit 问题

发布于 2024-08-29 04:13:16 字数 334 浏览 1 评论 0原文

我正在使用从 NSOperation 继承的对象进行下载。我已阅读文档,当我的操作完成时,我必须调用该

[self.delegate performSelectorOnMainThread:@selector(operationDidFinish:) withObject:self waitUntilDone:YES];

方法。它需要在主线程上调用,因为 UIKit 不是线程安全的,并且文档在这些非线程安全框架情况下说明了这一点。 在委托方法中,我正在绘制 pdf 或图像,但由于它是在主线程上绘制的,因此用户界面在绘制完成之前非常滞后。 也许你能建议我一个避免这个问题的好方法吗?

I am doing my download with an object which was inherited from NSOperation. I have read the documentation and when my operation finished I must call the

[self.delegate performSelectorOnMainThread:@selector(operationDidFinish:) withObject:self waitUntilDone:YES];

method. It needs to be called on the main thread, because the UIKit is not thread safe and the documentation says this in these non thread safe frameworks cases.
In the delegate method I am drawing a pdf or an image, but because it is drawn on the main thread the User Interface is very laggy until the drawing is finished.
Maybe can you suggest me a good way to avoid this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-09-05 04:13:16

我假设您正在下载图像数据、对其进行解码并渲染图像。最后一点,渲染,必须在主线程上发生。您可以将解码部分移至您的下载线程吗?例如,使用 CGImage 调用来解码 png 或 jpeg,因此您可以在调用 operationDidFinish 之前准备好使用 CGImageRef。如果您可以将 PDF 作为图像使用,那么转换它会比在主线程中解码它更好。

I am assuming you are downloading image data, decoding it, and rendering the image. The last bit, render, has to happen on the main thread. Can you move the decode part to your download thread? For example, use CGImage calls to decode a png or jpeg, so you have a CGImageRef ready to use before calling operationDidFinish. If you can work with the PDF as images, it would be better to convert it than decode it in the main thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文