分页不同页面宽度的UIScrollView
我想要一个水平滚动的 UIScrollView 并启用分页。该滚动视图中的页面具有不同的宽度,因此各个页面的滚动距离不同。
目标是为不同时间点制作一个选择器,例如:
| Now | Yesterday evening | Last Week | Last Month |
^ ^ ^ ^ <- stopps here
Here |现在 |
的宽度比 | 更小昨天晚上|
。当分页浏览这些值时,滚动视图应停止在相应值的中心。
这可能吗?
I would like to have a horizontal scrolling UIScrollView with paging enabled. The pages in this scrollview have different widths, so the scrolling distance differs from page to page.
The goal is to make a picker for different points in time, e.g.:
| Now | Yesterday evening | Last Week | Last Month |
^ ^ ^ ^ <- stopps here
Here | Now |
has a smaller width than | Yesterday evening |
. When paging through this values, the scrollview should stop at the center of the according value.
Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这当然是可能的,但不是那么自动...
我想你应该实现 UIScrollViewDelegate 协议方法:
这是当用户停止在滚动视图上移动手指时调用的方法,
您可以在其中检查内容的坐标:
然后检查 page.x 中的哪一个(在创建它们时将它们注册到数组中,或者检查添加到滚动视图的所有视图的原点)更接近它,然后转到页面的偏移量(带有动画)调用:
it's surely possible, but not so automatically...
i guess you should implement the UIScrollViewDelegate protocol method:
it's the method called when the user stop to move the finger on the scrollView,
you can check inside it the coordinate of your content:
and then check which one of your page.x ( register them in an array when you create them, or check the origin of all your view added to the scrollView) is closer to it, then go to the offSet of your page (with animation) calling: