views:

63

answers:

2

I have a horizontally scrolling UIScrollView and I want to display potentially thousands of UIImage's side by side. Obviously I can't do that for memory reasons so what I am thinking is set the content size to be the 2000 or whatever but only show the current window of image squares. So the user would flick the scroll bar and when it stops (it is paged so it will stop scrolling quickly), it will display the images that should be there at that point.

I haven't done that yet but sounds simple enough. I will just have 1 row of UIImage's moving around and loading different content depending upon which scrolling 'page' comes to rest.

First question - is that a good approach? Second question - how can I have an infinitely repeating tiled background image of empty squares or something to act as placeholders for content that hasn't been loaded. These will be displayed as the user is whirling the scroll bars around. Can we have a tiled BG image on UI elements?

A: 

paginating and a lot of content: only allocate and initalise those images that are close to the current you view. do some listening and calculate which page you are on and then fire those up. the content size can be as big as you want, doesen't matter if you do it like this.

Fossli
+1  A: 

Yes, this pretty much is the solution for this problem. Like Fossli said, you can have a massive content size and it won't make a difference, allocate the visible images and those near it, remove when they aren't needed. For a tiled bg image you could try setting the background color and creating a UIColor with [UIColor colorWithImage:myBgImage]

mbehan
Ok, great stuff (you and fossli) but will that BG image be moving when the user is quickly scrolling - giving the appearance of movement even though there is no content until it stops scrolling? And is it memory/cpu intensive to have a repeating BG image?
Mike Simmons
Just wrote a test on the tiled bg image and it doesnt work as i expected, (it tiles to fill the scroll views initially visible size, but not the whole content size so it appears to be static while scrolling). Having a massive image as the bg image would create the desired effect but would eat memory. I would recommend having the same small placeholder image for each image that is loaded before the main image, so during fast scrolling this would be visible before the main image loads.
mbehan
Or I guess I just forget fast scrolling and just stick to paging scrolling. Thanks so much for your research.
Mike Simmons