zoukankan      html  css  js  c++  java
  • 利用Scrollow写一个下拉刷新

    利用scrollView滑动的2个监听方法实现

    //滑动结束时候 出发的方法

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

        

        if (self.refreshLabel.tag == 1) {

            

            [UIView animateWithDuration:.3 animations:^{

    //            [self searchSevicePushData];

                self.refreshLabel.text = @"加载中...";

                

                scrollView.contentInset = UIEdgeInsetsMake(80.0f, 0.0f, 0.0f, 0.0f);

                

            }];

            

            //数据加载成功后执行;这里为了模拟加载效果,一秒后执行恢复原状代码

            

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

                [self loadSexButton];

                [UIView animateWithDuration:.3 animations:^{

                    

                    self.refreshLabel.tag = 0;

                    

                    self.refreshLabel.text = @"下拉刷新";

                    

                    scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

                    

                }];

                

            });

            

        }

        

    }

    //滑动过程中的监听方法 

    #pragma mark -UIScrollViewDelegate

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

        

    //    NSLog(@"滑动%f",scrollView.contentOffset.y);

            if (scrollView.contentOffset.y <= -70)

            {

                //        CGFloat y = fabs(scrollView.contentOffset.y);

                //        NSLog(@"%f",y);

                

                if (self.refreshLabel.tag == 0) {

                    

                    self.refreshLabel.text = @"松开刷新";

                    

                }

                self.refreshLabel.tag = 1;

                

            }else{

                

                //防止用户在下拉到contentOffset.y <= -50后不松手,然后又往回滑动,需要将值设为默认状态

                

                self.refreshLabel.tag = 0;

                

                self.refreshLabel.text = @"下拉刷新";

                

            }

        

        

    }

  • 相关阅读:
    闲话: 恭喜园子里的MVP一下, 同时问所有奋斗在技术领域的兄弟过节好~
    随便说两句: 表设计兼一些设计分析的讨论
    是他妈傻子写的么?
    Utility Wish List
    我终于有个偶像了
    也论标准: 统一是啥好事情?
    linux 编程学习笔记(1)搭建c(c++)开发环境
    Immutable Collections(2)ImmutableList<T>实现原理.(上)
    托管代码的进程注入&CLR宿主
    .NET安全揭秘系列博文索引
  • 原文地址:https://www.cnblogs.com/walkingzmz/p/scrollView.html
Copyright © 2011-2022 走看看