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

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

问题描述

我一直在尝试显示来自服务器的大图像,但我必须逐步显示它.

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

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

我在其中添加数据并将其转换为 UIImage 对象,并使用 UIImagedrawInRect: 方法绘制矩形.p>

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

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

任何帮助都将不胜感激.

didReceiveData 中是否有任何有效的方法来逐步绘制模糊图像?所以 drawInRect 不会花费太多时间来绘制.或者,如果有人有自定义的 drawRect 方法,该方法可以有效地将图像逐渐显示为在 didReceiveData 中接收到的数据.

解决方案

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

https://github.com/HubertK/ProgressiveImageDownload

它真的很容易使用,创建一个 NYXProgressiveImageView 对象,设置 URL,它会在您调用时为您完成所有工作:

loadImageAtURL:

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

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

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

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;

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?

Any help will be appreciable.

Edit: 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.

解决方案

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

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:

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天全站免登陆