Paging UIScrollView with different page widths(不同页面宽度的分页 UIScrollView)
问题描述
我想要一个启用分页的水平滚动 UIScrollView.此滚动视图中的页面具有不同的宽度,因此滚动距离因页面而异.
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.
这可能吗?
推荐答案
这当然是可能的,但不是那么自动......
it's surely possible, but not so automatically...
我猜你应该实现 UIScrollViewDelegate 协议方法:
i guess you should implement the UIScrollViewDelegate protocol method:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
}
当用户停止在scrollView上移动手指时调用的方法,您可以在其中检查内容的坐标:
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:
yourScrollView.contentOffset
然后检查哪一个 page.x(在创建它们时将它们注册到数组中,或检查添加到 scrollView 的所有视图的来源)更接近它,然后转到页面的 offSet(带动画)调用:
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:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
这篇关于不同页面宽度的分页 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不同页面宽度的分页 UIScrollView
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
