1

In my app, I use a scroll view in which I display 300 image (400 kB). It takes nearly 2 minutes, and as a result, when I scroll up and down, it isn't smooth.

How can I solve this problem?

Note: I have noticed that after I scroll down to end of scrollview once, it gets smooth. The issue with scrolling only appears the first time.

Jean
  • 7,623
  • 6
  • 43
  • 58
yatanadam
  • 1,254
  • 1
  • 11
  • 19

3 Answers3

0

Do not load all images upfront. Just load the images to show at the moment and the next + last picture.

As far as i understand you load all the images when the scrollview is loaded/displayed. Since you have a lot of images it will be much faster and much more memory saving if you just load/have in memory three images. This will be the previous/left shown image and not visible - the current shown and visible image and the next/right image which is not visible.

So if you move/swipe to the left you basicly move the scrollview to the left and show the right image which is already loaded. In the background you will load the next right image while you will deallocate the left most image.

At all times you just have maximal 4 images loaded.

Take a look at the infinite scrollview example of WWDC 2011 - Session 104 advanced scroll view for a good visual example and sample code.

Pfitz
  • 7,336
  • 4
  • 38
  • 51
0

I think this will solve your problem. This question may give you some context:

How to reuse/recycle custom element like uitableviewcell does?

Community
  • 1
  • 1
Sailesh
  • 25,517
  • 4
  • 34
  • 47
0

Try adding this in your load function (where you load your images). If you are using a while or for loop to load images, add this code to the loop.

NSURL *url=//here url for your image   
dispatch_queue_t currentQueue = dispatch_get_current_queue();
dispatch_queue_t dataConvertorQueue = dispatch_queue_create("Fetching images", NULL);
dispatch_async(dataConvertorQueue, ^{
    NSData *data = [NSData dataWithContentsOfURL:url];
    dispatch_async(currentQueue, ^{
       //replace imageView with your imageView outlet
       imageView.image = [[UIImage alloc] initWithData:data]];
    });
});
dispatch_release(dataConvertorQueue);

This code helps you fetch and show images from a url and it works great with a tableview. It might not be exactly what you want but it'll give you an idea on how to do it. Hope it'll help you.

Anila
  • 1,136
  • 2
  • 18
  • 42