ScrollView分页-无限循环

Posted 华少不思议

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ScrollView分页-无限循环相关的知识,希望对你有一定的参考价值。

#import "XMGInfiniteScrollView.h"

static int const ImageViewCount = 3;

@interface XMGInfiniteScrollView()

@property (weak, nonatomic) UIScrollView *scrollView;

@property (weak, nonatomic) NSTimer *timer;

@[email protected] XMGInfiniteScrollView

- (instancetype)initWithFrame:(CGRect)frame

{    if (self = [super initWithFrame:frame]) {        // 滚动视图        UIScrollView *scrollView = [[UIScrollView alloc] init];        scrollView.showsHorizontalScrollIndicator = NO;        scrollView.showsVerticalScrollIndicator = NO;        scrollView.pagingEnabled = YES;        

scrollView.bounces = NO;      

  scrollView.delegate = self;        

[self addSubview:scrollView];   

     self.scrollView = scrollView;             

   // 图片控件   

     for (int i = 0; i- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{    // 找出最中间的那个图片控件  

  NSInteger page = 0;    CGFloat minDistance = MAXFLOAT;

    for (int i = 0; i= self.pageControl.numberOfPages)

 {

index = 0;

}

imageView.tag = index;

imageView.image = self.images[index];

}

// 设置偏移量在中间

if (self.isScrollDirectionPortrait) {

self.scrollView.contentOffset = CGPointMake(0, self.scrollView.frame.size.height);

} else {

self.scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width, 0);

}

}

#pragma mark - 定时器处理

- (void)startTimer

{

NSTimer *timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(next) userInfo:nil repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

self.timer = timer;

}

- (void)stopTimer

{

[self.timer invalidate];

self.timer = nil;

}

- (void)next

{

if (self.isScrollDirectionPortrait) {

[self.scrollView setContentOffset:CGPointMake(0, 2 * self.scrollView.frame.size.height) animated:YES];

} else {

[self.scrollView setContentOffset:CGPointMake(2 * self.scrollView.frame.size.width, 0) animated:YES];

}

}

@end

以上是关于ScrollView分页-无限循环的主要内容,如果未能解决你的问题,请参考以下文章

当没有更多数据时如何停止无限循环(分页)

使用三个视图的无限循环分页 UIScrollView

iOS: 无限循环轮播图简单封装

unity的ugui-8.scroll view无限循环列表

如何可视化vue无限更新循环的无限循环

无限循环与嵌套循环