UIImage将从服务器逐步显示 [英] UIImage to be displayed progressively from server

查看:145
本文介绍了UIImage将从服务器逐步显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从服务器显示大图像,但我必须逐步显示它。

I have been trying to display large image from server, but I have to display it progressively.

我使用了UIView的子类,并且我已经使用 UIImage 对象,其中我使用了NSURLConnection及其委托方法,我也使用了

I used subclass of UIView and in that I have taken UIImage object, in which I used NSURLConnection and its delegate methods, I also used

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

我追加数据并将其转换为 UIImage object,并使用 drawInRect:方法 UIImage 绘制rect。

in which I am appending data and converting it to UIImage object, and drawing rect using the drawInRect: method of UIImage.

一切正常,但问题是,当在上下文中绘制图像时,我无法点击屏幕上的任何其他位置,直到将整个图像绘制到屏幕上。

Everything is working fine, but the problem is, when image is being drawn on context, I cannot click anywhere else on screen until entire image is being drawn on to screen.

有没有什么好的解决方案,即使在屏幕上绘制图像,我还可以点击其他地方?

Is there any good solution, where I can click anywhere else even if image is being drawn on screen?

任何帮助都会很明显。

编辑:
是否有任何有效的方法在 didReceiveData 中逐步绘制图像模糊?所以 drawInRect 不需要太多时间来绘制。或者,如果有人有自定义 drawRect 方法,它会在 didReceiveData 中收到的数据中逐步有效地显示图像。

Is there any efficient way of drawing image blurry progressively in didReceiveData? so drawInRect does not take too much time to draw. Or If anyone has custom drawRect method which efficiently displays image progressively as data received in didReceiveData.

推荐答案

我已经使用NYXImagesKit做类似的事情,下载图像而不阻塞主线程并逐步显示图像。我写了一个非常快速和肮脏的例子来说明基本的工作原理。我在UITableview中加载图像,以显示它不会阻止用户界面(主线程)。您可以在加载图像时滚动桌面视图。不要忘记添加正确的框架,有几个。下面是Github项目的链接:

I have used NYXImagesKit for something similar, downloading images while not blocking the main thread and showing the image progressively. Ive written a really quick and dirty example to illustrate the basic workings. I load the image in a UITableview to show that it doesn't block the User Interface(Main Thread). You can scroll the tableview while the image is loading. Don't forget to add the correct Frameworks, there are a few. Heres the link to the project on Github:

https:/ /github.com/HubertK/ProgressiveImageDownload

它非常易于使用,创建一个NYXProgressiveImageView对象,设置URL并为您完成所有工作当你打电话:

It's really easy to use,create a NYXProgressiveImageView object, set the URL and it will do all the work for you when you call:

loadImageAtURL:

它是UIImageView的子类,像魔术一样工作!这是开发者网站的链接:

It's a subclass of UIImageView, Works like magic! Here's a link to the developers site:

http://www.cocoaintheshell.com/2012/01/nyximageskit-class-nyxprogressiveimageview/

这篇关于UIImage将从服务器逐步显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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