zoukankan      html  css  js  c++  java
  • ScrollView定时器复用

    起始偏移量设置为一个宽度

            [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(refreshPic) userInfo:nil repeats:YES];

      

    //定时器实现

    - (void)refreshPic{

        if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width==4) {

            _mainScrollView.contentOffset = CGPointMake(0, 0);

        }

            [_mainScrollView setContentOffset:CGPointMake(_mainScrollView.frame.size.width+_mainScrollView.contentOffset.x, 0) animated:YES];

        self.pageCor.currentPage = _mainScrollView.contentOffset.x/_mainScrollView.frame.size.width;

    }

    //手动拖拽实现

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

        if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width == 5) {

            

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

            self.pageCor.currentPage = 0;

        }else if (_mainScrollView.contentOffset.x/_mainScrollView.frame.size.width==0){

            _mainScrollView.contentOffset = CGPointMake(_mainScrollView.frame.size.width*4, 0);

            self.pageCor.currentPage = 3;

        }else{

            self.pageCor.currentPage = _mainScrollView.contentOffset.x/_mainScrollView.frame.size.width-1;

        }

    //定时器触碰停止,3秒后自动启动

    - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

        

        _timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];

    }

    }

  • 相关阅读:
    Java多线程之二:Thread
    并发编程之Future/FutureTask/CompletionService/CompletableFuture
    Java8使用并行流(ParallelSream)
    IDEA 运行报Command line is too long解法
    Comparator VS Comparable
    设计模式6-观察者模式
    设计模式-策略模式VS工厂模式
    设计模式4-策略模式
    设计模式5-代理模式
    设计模式3-工厂模式
  • 原文地址:https://www.cnblogs.com/block123/p/4912383.html
Copyright © 2011-2022 走看看