使UIScrollView环绕 [英] Make UIScrollView wrap around

查看:105
本文介绍了使UIScrollView环绕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

UIScrollView。关于实现无限的任何想法滚动/缩放?

我有一个UIScroll有八个左右的页面。我的目标是让他们循环,以便当用户到达最后一页时,第一页将是下一页(反之亦然),以便用户可以无休止地滚动页面。什么是实现这个的最好的方法?

I have a UIScroll which has eight or so pages. My aim is for them to 'loop' around so that when the user reaches the last page the first page will be the next page (and vice versa) so that the user could scroll through the pages endlessly. What is the best way to achieve this?

我正在使用此例子从可可与爱。

I am working from this example from Cocoa with Love.

任何帮助都非常感谢。谢谢。

Any help is greatly appreciated. Thank you.

推荐答案

问题现在排序。基本上,我在我的页面之前和之后创建了额外的页面,因此它看起来像这样:

Problem is sorted now. Basically, I created extra pages before and after my pages so it looks like this:


8 1 2 3 4 5 6 7 8 1

8 1 2 3 4 5 6 7 8 1

然后在 scrollViewDidEndDecelerating 中,我做一个简单的if语句,在第一页或最后一页,并适当地定位 scrollView

Then in the scrollViewDidEndDecelerating I do a simple if statement that checks if I am at either the first or last page and locate the scrollView appropriately.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)newScrollView
{
    [self scrollViewDidEndScrollingAnimation:newScrollView];
    pageControl.currentPage = currentPage.pageIndex;

    if(currentPage.pageIndex==0){
        scrollView.contentOffset = CGPointMake(320*(pageControl.numberOfPages-2), 0);
        pageControl.currentPage = pageControl.numberOfPages-2;
    }else if(currentPage.pageIndex==pageControl.numberOfPages-1){
        scrollView.contentOffset = CGPointMake(320, 0);
        pageControl.currentPage = 1;
    }

}

这篇关于使UIScrollView环绕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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