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

                }
            }
            
        }
    }

  • 相关阅读:
    20200226 Java IO流——廖雪峰
    20200225 Java 多线程(2)-廖雪峰
    20200225 Java 多线程(1)-廖雪峰
    20200224 尚硅谷ElasticSearch【归档】
    20200224 一 概述
    20200222 尚硅谷Dubbo【归档】
    20200222 四、dubbo原理
    Improved robustness of reinforcement learning policies upon conversion to spiking neuronal network platforms applied to Atari Breakout game
    Reinforcement learning in populations of spiking neurons
    Solving the Distal Reward Problem through Linkage of STDP and Dopamine Signaling
  • 原文地址:https://www.cnblogs.com/allanliu/p/4512231.html
Copyright © 2011-2022 走看看