重新创建 UIPickerView 仅显示一行

发布于 2024-11-15 14:07:19 字数 678 浏览 2 评论 0原文

我需要一个“PickerView”,其行为类似于普通的 UIPickerView,但仅显示一行数据并具有自定义设计。

就像您在图像中看到的那样,显示从子视图 1 到子视图 2 的过渡。用户抬起手指并滚动停止后,将仅显示一个子视图:

IMAGE

所以基本上是一个滚动视图:

  • 通过一遍又一遍地显示相同的条目,在正向和负向上都是无限

  • 在多个子视图中使用分页

  • 不滚动时仅显示一个子视图,滚动时不超过两个子视图。

我可以让无限滚动视图工作,但不能启用分页。分页总是会限制我滚动到下一个子视图。

所以我正在考虑创建我自己的 UIView 子类,它自定义滚动行为来模仿 UIPickerView。但在此之前,我想获得一些关于这个想法的总体意见。创建自定义 UIView 是正确的方法吗?有人对预期性能有一些经验吗? (会有计时器来处理滚动算法,当然必须重新创建......:)

另一种方法是子类化 UIScrolView 并自己实现分页。我知道滚动视图何时开始减速 ,所以也许有一种方法可以覆盖 contentOffset 以使其滚动到正确的位置...?!

任何帮助表示赞赏!谢谢!

I need a "PickerView", that behaves like a normal UIPickerView, but only shows one row of data and has a custom design.

Something like you see in the image, showing the transition from subview 1 to subview 2. After the user lifts his finger and after the scrolling stops, only one subview will be shown:

IMAGE

So basically a scrollview which:

  • is endless in both, positive and negative directions by showing the same entries over and over

  • uses paging across several subviews

  • only shows one subview when not scrolling, and no more than two subviews when scrolling.

I can get a endless scrollview to work, but not with paging enabled. Paging will always limit my scrolling to the next subview.

So I'm thinking about creating my own UIView subclass which custom scrolling behaviour to mimic a UIPickerView. But before doing so, I wanted to get some opinions about the idea in general. Is creating a custom UIView the right way to go? Anyone has some experience with the expected performace? (There will be timers to handle the scrolling algorithm, which has to be recreated of course... :)

Another approach would be to subclass UIScrolView and implement the paging myself. I know when the scrollView starts decelerating
, so maybe there is a way to overwrite the contentOffset to have it scroll into the right position...?!

Any help is appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞取 2024-11-22 14:07:19

这是一个很棒的自定义组件,它似乎能够完成您需要的一切:

http://dev.doukasd.com/2011/04/infinite-scrolling-dial-control-for-ios/

它不是无限的,而是修改过的UITableView 具有大量单元格。

Here is a great custom component, which seems to be able to do everything you need:

http://dev.doukasd.com/2011/04/infinite-scrolling-dial-control-for-ios/

It's not endless, but rather a modified UITableView with a huge number of cells.

单身狗的梦 2024-11-22 14:07:19

仅使用 UIPickerView 但剪裁到中间行是否可行?您可以关闭 showsSelectionIndicator 以删除叠加层并让委托传回自定义行视图。

Would it be feasible to just use a UIPickerView, but clipped to the middle row? You could turn off showsSelectionIndicator to remove the overlay and have the delegate pass back custom row views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文