Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
466 views
in Technique[技术] by (71.8m points)

iphone - Paging UIScrollView with different page widths

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

it's surely possible, but not so automatically...

i guess you should implement the UIScrollViewDelegate protocol method:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

}

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...