我怎么能做无限卷轴?

时间:2013-12-16 14:04:54

标签: ios uiscrollview infinite-scroll

我有一个自动将图像传递给另一个的scrollview。它有7个图像,我想要当你到达第七个图像时,以与其余过渡相同的方式向我传递第一个图像  而不是迅速移动到第一个位置。

这就是通常所说的无限滚动。任何帮助表示赞赏。

- (void)viewDidLoad
{

for (int i = 1; i < 8 ; i++) {

    UIImageView *imagen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"C%d.png",i]]];

    imagen.frame = CGRectMake((i-1)*580,35, 580, 300);

    [_scroller addSubview:imagen];

    _scroller.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}


_scroller.delegate = self;
_scroller.contentSize = CGSizeMake(580*7, 300);
_scroller.pagingEnabled = YES;

if (scrollingTimer == nil)
{
    scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:6
                                                      target:self selector:@selector(scrollPages) userInfo:nil repeats:YES];
}
}

-(void)scrollToPage:(NSInteger)aPage{
float myPageWidth = [_scroller frame].size.width;

[_scroller setContentOffset:CGPointMake (aPage * myPageWidth, 0) animated:YES];

}

-(void)scrollPages{
[self scrollToPage:currentPage%7];
currentPage++;
}

1 个答案:

答案 0 :(得分:1)

在分页UIScrollView中实现无限分数的一种方法是在滚动视图的末尾放置第一页的副本(反之亦然,如果你想在两个方向上无限滚动)。

This article使用UICollectionView代替,但分页UIScrollView的概念相同。当用户在滚动视图的末尾滚动到第一页的副本时,将内容偏移设置回实际的第一页(没有动画,因此用户不知道它发生了)。

以下是我认为有用的其他一些资源:

相关问题