Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

iphone - UIImage to be displayed progressively from server

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...