开发者

iPhone: Infinitely looping content inside UIScrollView

In my app, I'm designing a custom picker that allows the user to choose an item by scrolling horizontally and touching it. I need the buttons inside that view to loop around infinitely as the us开发者_Go百科er scrolls in a certain direction. What would be the best way to tackle this feature while maintaining the inertial scrolling of UIScrollView when the content loops around out of the view?

From my research of others trying to attempt this, they have trouble maintaining the deceleration animation if the scroll position is programatically shifted mid-scroll after the user lifts their finger. How can I work around this limitation?

An example of an app that currently has this feature is Apple's MobileMe Gallery app. In the interface, after choosing a gallery, at the top, there is a horizontally scrollable photo picker that loops infinitely as it is dragged one direction.

Any advice is greatly appreciated.


I wrote a general-purpose carousel control that can handle this sort of requirement easily and uses a simple datasource/delegate pattern for supplying the content views:

http://charcoaldesign.co.uk/source/cocoa#icarousel

I did use a UIScrollView as the basis originally, but that was fairly limiting so in the latest version I just manage the acceleration myself.


Here is some sample code that does what you want :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜