views:

129

answers:

1

What I'm trying to do is to implement something like the fruit machine scroll view. Basically I have a sequence of images (randomly generated on the fly) and I want to allow the users to scroll through this line. There can fit approx 10 images on the screen, but the line is virtually unlimited.

My question is what would be the best approach in implementing this?

So far I've thought of having a UIImageView going across the screen (with width equal to the sum of 10 images) and the image associated with it would be a combination of 12 or so images, with two images falling out of the visible area, this would allow for smooth scrolling. If the user scrolls further, then I would reconstruct the image associated with the view so the new images are appended and the old one's are discarded.

This image reconstruction business sounds bit complicated, so I was wondering if there's a more logical way to implement this.

There's one more thing, I want to have two lines crossing each other with images, bit like conveyor belts crossing. If that makes any sense... Bit like below:

      V1
      V2
H1 H2 H3 H4 H5
      V4
      V5

So if the vertical belt is moved it'd be like:

      V2
      H3
H1 H2 V4 H4 H5
      V5
      V6

H1-H5, V1-V6 being automatically generated images.

I'm not asking for the implementation code, just the thoughts on the principles how to implement this. Thanks!! :)

+1  A: 

I would just keep them all as separate UIImageViews and animate them in concert (using UIView animations). That way you let CoreAnimation take care of rendering into layers. Once an image goes offscreen you can destroy it - and create new ones ready to come onscreen at the other end. A more sophisticated approach would involve a pool of offscreen UIImageViews so you don't immediately destroy (and may never destroy). That would be somewhat like the way a UITableView is implemented - only you'd be rolling your own (if it was just vertical columns I'd suggest UITableViews).

If I get what you're trying to do I think the performance should be fine.

Phil Nash
So you mean each individual image would be an instance of UIImageView? And if so, it'd be the underlying view object that is reacting to the user commands (touchesmove, etc)?
pulegium
each image would be placed in an individual `UIImageView`, yes. Whether you hook the touches through those image views, or let them pass through to a(n invisible) container view behind is up to you.
Phil Nash
Excellent, I'll use this as a starting point, thanks!
pulegium