views:

201

answers:

1

Hi all, I'm trying to figure out if I can get what I want out of UIScrollView through some trickery or whether I need to roll my own scroll view:

I have a series of items in row that I want to scroll through. One item should always be centered in the view, but other items should be visible to either side. In other words, I want normal scrolling and edge bouncing, but I want the deceleration when the user ends a touch to naturally settle at some specified stop point. (Actually now that I think of it, this behavior is similar to coverflow in this respect.)

I know UIScrollView doesn't do this out of the box, but does anyone have suggestions for how it might be made to do this, or if anyone's spotted any code that accomplishes something similar (I'm loathe to reimplement all the math for deceleration and edge bounce)

Thanks!

+3  A: 

There is not a whole lot of trickery to this. Just use an UIScrollView with paging enabled. Make it the size of one of your items, and locate it where you want that item to appear. Next, disable the "Clip Subviews" option on the scroll view (either in IB, or programmatically), and you are all set.

Johan Kool
This is a great suggestion-- had definitely not thought of this. However, only the window where the "current" item is visible is touchable in this case. Even though the other items in the "carousel" are visible, the scrollview doesn't know they're there. I tried setting up a transparent backing view to grab all those touches and send them to the scroll view, but the scrollview doesn't seem to be interested. Thoughts?
quixoto
I resolved that by putting some transparent buttons there. If the user taps there, I let the scrollview show the next (or previous) item. Works pretty intuitive, where I used it.
Johan Kool