• 根据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(@"右切换");
                    }

                }
            }
            
        }
    }

  • 相关阅读:
    torch 入门
    编译CDH Spark源代码
    Marsedit 破解版下载(3.5.6)
    程序员必备:技术面试准备手册
    360私有化详细资料曝光:抵押总部大楼(转)
    底层软件工程师的一次冒险经历
    这十种算法撑起了整个世界
    秒杀系统架构分析与实战(深度学习资料)
    北京程序员 VS 硅谷程序员(转)
    Timestamp 使用
  • 原文地址:https://www.cnblogs.com/allanliu/p/4512231.html
Copyright © 2020-2023  润新知