使用不同的页面宽度分页UIScrollView [英] Paging UIScrollView with different page widths

查看:131
本文介绍了使用不同的页面宽度分页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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆