On Jul 31, 2012, at 03:52 , Dave <d...@looktowindward.com> wrote:

> Basically I have process that generates UIImage's and each of these images 
> needs to be presented in a Scroll View. However there can be a large number 
> of images generated and each image is pretty big too, so obviously, it can't 
> hold them all in RAM. My idea is to keep a number of images (say 5) cached 
> and as the user scrolls, generate the next or previous image and discard the 
> old one.

Remember that scrolling can accelerate if the user keeps swiping, which means 
that scrolling doesn't necessarily display *every* view of the sequence.

If the time it takes to create the view is short (less than the display refresh 
time), then there's no point in caching "nearby" images at all, at least from a 
scrolling point of view. You can simply recreate images as they are needed.

If -- the more likely scenario -- it takes longer to create the images, then 
caching the images isn't really going to solve the performance problem either, 
because that would require the cache to correctly predict what images are 
*going to* be needed, and have enough advance warning to be able to load up the 
cache *before* the images are needed. Your intended caching mechanism will fail 
in the case where the failure is probably most noticeable to the user -- the 
fast, continuous scrolling I already mentioned.

For those reasons, I'd suggest you'd be better off creating the images on 
demand, in a background thread, and drawing them when they become available. 
(You can create a low-resolution version or a partial representation of the 
data to display immediately, if that can be done fast enough.)

Such an approach, combined with the 3-views scrolling technique (to keep the 
memory usage down), should give you a good solution.

IDK either where sample code disappears these days, but watch the 2011 WWDC 
session video on using scroll views. It walks through the process of 
configuring such a view (it's fairly simple, and you can pretty much write your 
own code while watching). If you want to see how iOS 6 will simplify things a 
bit more, watch the beginning of the 2012 session on the same subject. I'd also 
highly recommend the 2012 WWDC session on concurrent user interfaces -- why, 
when and how you might move drawing to the background.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to