views:

791

answers:

3

What's the simplest way to have a scroll view (with pagingEnabled set to YES) have a page width set to something other than the scroll view's bounds?

Let me give an example. Suppose I have a scroll view with 10 items, each 150 pixels wide, and my scroll view is 300 pixels wide. If I start with views 1 and 2 visible and scroll horizontally to the right, I want the next "page" to show items 2 and 3. If I scroll one more page to the right, I would see items 3 and 4.

Has anyone done this? If not, what strategy would you use?

+4  A: 

Alexander Repty just blogged about this very topic: http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html. Short answer: it's not as simple as just changing the width of the 'page', but it's not too hard.

Ben Gottlieb
I've seen this approach mentioned elsewhere and tried it, but unfortunately I don't think it does what I want. I need more than to see the edges of the surrounding items - In my case, I need to have two items fully on screen. This approach unfortunately didn't work too well for me, especially on the very leftmost/rightmost edges.
Mike McMaster
Just make your scrollview 150px wide, but turn off clipping. Put the whole thing inside a view that's 300 px wide, and turn ON clipping for it.
Ben Gottlieb
Thanks, Ben. As I mentioned in my comment on Alexander's answer, this definitely put me on the right path.
Mike McMaster
+1  A: 

Mike,

use the approach from my blog that Ben linked you to. Make the UIScrollView half the size of the surrounding view (i.e. 150px) and move it to the left instead of leaving it centered.

That should give you exactly the behaviour you wanted.

Cheers, Alex

Alexander Repty
It wasn't quite that simple, but I believe I've got it figured out. Your post certainly helped - thank you!
Mike McMaster
A: 
Susanna
I wouldn't say that at all. The default behavior is helpful for lots of use cases. As for why it's not configurable... it'd be easy for me to believe that it's because Apple, in its quest for UI consistency and quality, would prefer not to make it easy for developers to create scroll views that have strange/ugly behavior.
Mike McMaster