Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS app : lag issue when display a huge amount of small images
    text
    copied!<p><strong>Environment:</strong></p> <p>I am creating a "<a href="https://www.google.com/search?num=10&amp;hl=fr&amp;safe=off&amp;authuser=0&amp;site=imghp&amp;tbm=isch&amp;source=hp&amp;biw=1294&amp;bih=738&amp;q=photo+mosaic&amp;oq=photo+mosaic&amp;gs_l=img.3..0l2j0i24l8.1141.1141.0.2483.1.1.0.0.0.0.52.52.1.1.0...0.0...1ac.2.0gxiTdE3WNE" rel="nofollow">photo mosaic</a>" 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.</p> <p><strong>Issue:</strong></p> <p>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).</p> <p><strong>What I think:</strong></p> <p>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.</p> <p>So any idea about it? Any, any idea will be helpful.</p> <p>Thanks so much,</p> <p><strong>UPDATE</strong></p> <p>It is much better after I took the advice from @Antwan van Houdt . Here is the principle code:</p> <pre><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(); } </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload