views:

119

answers:

2

Hello, I am trying to create an inifite timeline in my iPhone app to scroll through time. I think I am going to use a UIScrollView to do that but I am not sure how to do that.

Am I supposed to create a reusable queue of views from scratch with views containing the days/months/years and reuse them when they go out of the screen ? (I have in mind the reusable cells from the tableviews).

Maybe there is a better way to do that ? Thanks for your help !

A: 

Well, the UIScrollView is finite, so you will hit the end at one point. You can of course move items around (back) to make sure you will never hit that limit.

You certainly want to do some caching/paging ala UITableView to make sure you only keep the minimal needed views in memory.

Ask a more specific question if you are ready for that :-)

St3fan
+1  A: 

As far as I know, UIScrollView doesn't have width limitation since 3.0. Nevertheless, you cannot use it to display large amount of data because it would take too much time to draw it and your application will work slow.

You can use UIView of width = 320.0 * 3 instead. Handle

- (void) touchesMoved: (NSSet*)_touches withEvent: (UIEvent*)_event

And apply

view.transform = CGAffineTransformMakeTranslation(-shift, 0.f);

Shift here can be calculated depending on delta X found from touches set. Affine translation allows to emulate smooth movement. When user releases their finger (touchesEnded), redraw your view (setNeedsDisplay) with shifted content and get it back:

self.transform = CGAffineTransformIdentity;

Don't do setNeedsDisplay while touchesMoved because it can affect performance if you are drawing graphs or calculating something.

For 2D map you would have to think about both X and Y and have 320*3 X 480*3 view :)

It's interesting task. Enjoy.

Pavel