zoukankan      html  css  js  c++  java
  • ScrollView分页-无限循环

    #import "XMGInfiniteScrollView.h"

    static int const ImageViewCount = 3;

    @interface XMGInfiniteScrollView()

    @property (weak, nonatomic) UIScrollView *scrollView;

    @property (weak, nonatomic) NSTimer *timer;

    @end@implementation 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

  • 相关阅读:
    linux如何查看端口或服务被占用情况
    linux网络查看及配置相关命令
    linux查看程序运行相关命令
    shell脚本编写一个用真实用户去访问的vsftpd服务器
    shell脚本监控CPU和内存利用率
    小白的个人技能树(基于自动化软件测试开发实习和软件开发实习)
    MySQL 8.0.12 基于Windows 安装教程(超级详细)
    C语言 0x7fffffff是多少(也就是INT_MAX,首位是 0,其余都是1,f代表1111)
    数通知识点
    数据结构之算法基础
  • 原文地址:https://www.cnblogs.com/CJH5209/p/6027441.html
Copyright © 2011-2022 走看看