I am working on an iPhone app which is related to stock market.
There is a requirement to create a horizontal scroller which is similar to a stock ticker.
What should I do to achieve that?
This sort of thing is a damn nuisance and (as far as I know) there is no easy existing way.
First you must simplify K.I.S.S. by making each block the same length. Here's how to do it..
(1) make a standard width (say, 100 px) for each "block".
The blocks would simply be UIViews (or perhaps just text labels). Are you comfortable with creating UIViews on the fly? If not we will tell you how to do it!
(2) pick a start point for the journey which is just to the right completely offscreen
(3) pick an end point for the journey which is just to the left completely offscreen
(3b) choose the exact time (say "4.71937s") you want for the travel time from point1 to point2
(4) figure out precisely (as in exactly precisely!) the seconds it takes for the block to travel it's own length from right to left. let's say 0.91763 seconds
You have to use NSTimers to do this. Are you familiar with them?
(5) set up a recurring 0.91763s timer which: makes a new block and
(5b) sucks off the next, if any, piece of text information (say "AAPL 408.50") and
(5c) places it at the start point2 and
(5d) simply using core animation begins it animating towards the end point3 and
(5e) launch an individual one shot timer for this block, which will destroy this block after the overall time mentioned in 3b
That's it.
You will have to set up a simple FIFO stack for the text items (whatever you you choose), as you get them from whatever source, shove them in to it.
Are you comfortable setting up some sort of array to use as a stack of info? Again if not we can help! :)
Note that in (5b) you would likely shove the one you just used back on the other end of the stack so they all keep going forever. It's quite likely you would have to be able to touch individual items to delete them or, eg, modify the price or whatever as new info comes in.
Once you get this working ("standard block length method"). You may prefer to somehow work out the exact length of each text block (AAPL 400.50 is longer than AAPL 30)...to do so...
Calculate on the fly a new own-length time value (as in point 4) for each block just for that block. ie, do that at point 5.b.2. instead of using a recurring timer (in point 5), fire off a new timer (at 5f) to launch the next block. (To be clear, points 3b and 5e are unchanged.)
Hope it helps!