zoukankan      html  css  js  c++  java
  • 根据UIScrollView 滑动获取当前页数

    #pragma mark --
    #pragma mark --  UIScrollViewDelegate
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        
        CGFloat pageWidth = mainScrollView.frame.size.width;
        
        int currentPage = floor((mainScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
       

        if (currentPage == _fullImagesArray.count - 1) {
            NSLog(@"---最后一页---");
        }else if (currentPage == 0){
            NSLog(@"---第一页---");
        }else{
            NSLog(@"---中间页---");
        }
        
    }

    #pragma mark - UIScrollViewDelegate
    #pragma mark - 左右滑动事件
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        static float newX = 0;
        
        if(scrollView == wmScrollView) {
            CGFloat pageWidth = wmScrollView.frame.size.width;
            int currentPage = floor((wmScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
            pageControl.currentPage = currentPage;
           
            NSArray *wmScrollViewSubViews = [wmScrollView subviews];
            NSInteger count = [wmScrollViewSubViews count];
            
            NSLog(@"------ currentPage :%d , count:%d",(int)currentPage,(int)count);
            
    //        if (currentPage == count) {
    //        float itemWidth = Main_Screen_Width/5.0;
    //            NSLog(@"----移动---");
    //            //移动下面的 tabbarScrollView
    //            [tabbarScrollView setContentOffset:CGPointMake(pageWidth, 0) animated:YES];
    //        }
            
            //判断左右滑动
            newX = scrollView.contentOffset.x;
            if (newX != _oldX) {
                if (newX > _oldX && (newX - _oldX) > 100) {
                    NSLog(@"左");
                    _oldX = newX;
                    if (currentPage == count-1) {
                        //切换
                        NSLog(@"左切换");
                    }
                    
                } else if (newX < _oldX && (_oldX - newX) > 100) {
                    NSLog(@"右");
                    _oldX = newX;
                    if (currentPage == 0) {
                        //切换
                        NSLog(@"右切换");
                    }

                }
            }
            
        }
    }

  • 相关阅读:
    hadoop学习笔记(十):MapReduce工作原理(重点)
    hadoop学习笔记(九):MapReduce程序的编写
    hadoop学习笔记(八):MapReduce
    hadoop学习笔记(七):Java HDFS API
    hadoop学习笔记(六):HDFS文件的读写流程
    hadoop学习笔记(五):HDFS Shell命令
    hadoop学习笔记(四):HDFS
    hadoop学习笔记(三):hadoop文件结构
    立即执行函数
    let命令
  • 原文地址:https://www.cnblogs.com/allanliu/p/4512231.html
Copyright © 2011-2022 走看看