在我的应用程序中,我正在设计一个自定义选择器,允许用户通过水平滚动并触摸来选择项目。当用户向某个方向滚动时,我需要该视图内的按钮无限循环。当内容在视图外循环时,解决此功能同时保持 UIScrollView 惯性滚动的最佳方法是什么?
根据我对其他尝试这样做的人的研究,如果在用户抬起手指后以编程方式在滚动中间移动滚动位置,他们将难以维持减速动画。我该如何解决这个限制?
目前具有此功能的应用示例是 Apple 的 MobileMe Gallery 应用。在界面中,选择图库后,顶部有一个可水平滚动的照片选择器,向一个方向拖动时会无限循环。
非常感谢任何建议。
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 user 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.
发布评论
评论(2)
我编写了一个通用轮播控件,可以轻松处理此类需求,并使用简单的数据源/委托模式来提供内容视图:
http://charcoaldesign.co.uk/source/cocoa#icarousel
我最初确实使用 UIScrollView 作为基础,但这相当有限,所以在最新版本中我只管理我自己加速。
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 :-)