Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app : lag issue when display a huge amount of small images

Environment:

I am creating a "photo mosaic" app, and I try to display 1024(32*32) pieces of small images(retina size->w:30px h:20px) on the screen same time. Which means on total, it is the same size as the full screen image size.

Issue:

I load 1024 UIImages, create 1024 UIImageViews, and add all of them to a UIView. When I scroll to this view, there is a big lag: test on iPhone4(iOS 5) and iPhone5(iOS 6). It's just appear on iPhone4, and on iPhone5 is fine. (Supposing iPhone5 have much more better CPU, so I think it is reasonable).

What I think:

Supposing all images have been already loaded from local dir in the memory(using method "imageNamed"), so I think the problem must be in the somewhere of the step display/render the images.

So any idea about it? Any, any idea will be helpful.

Thanks so much,

UPDATE

It is much better after I took the advice from @Antwan van Houdt . Here is the principle code:

-(void)updateCoverImageView:(UIImageView *)smallImage{
    UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0f);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [self.coverImageView.layer renderInContext:ctx];
    [smallImage.image drawInRect:smallImage.frame];
    self.coverImageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

Then you just set the alpha value of smallImage to zero, so the system won't render them. And the cover image will replace it. That works for the lag issue caused by displaying a large amount of UIView same time.

like image 739
swang Avatar asked Dec 29 '25 17:12

swang


1 Answers

Is every image in its own view?

In either case, for such a huge amount of images you should probably consider drawing them in 1 view and if that drawing method is still too slow you could draw it once, render the view to an image and then simply draw that image as it's cached display.

There are several guides available from apple that deal with the performance of custom view drawing and stuff like it.. you should give them a read.

like image 117
Antwan van Houdt Avatar answered Jan 01 '26 08:01

Antwan van Houdt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!