• iOS-SVPullToRefresh​下拉刷新,上拉加载(转)


    https://github.com/Sephiroth87/ODRefreshControl 类似刷新控件,类似qq动画的那种刷新。

    一.下载第三方库

    https://github.com/samvermette/SVPullToRefresh

    二.使用方法

    1.导入下载的第三方库

    2.导入头文件

    在需要的类里导入这一个头文件就能,同时使用下拉刷新,上拉加载

    #import "SVPullToRefresh.h"

     

    3.下拉刷新

    1. [_tableView addPullToRefreshWithActionHandler:^{  
    2.         //数据的加载,和表的刷新的代码。  
    3.         //全部需要我们自己写  
    4. //        [self refreshTableView];  
    5.         //3秒后调用refreshTableView方法  
    6.         [self performSelector:@selector(refreshTableView) withObject:nil afterDelay:1.0];  
    7. //        //风火轮的动画还需要我们手动的停止  
    8. //        [_tableView.pullToRefreshView stopAnimating];  
    9.     }];  

    4.上拉加载

    1. [_tableView addInfiniteScrollingWithActionHandler:^{  
    2.         [self performSelector:@selector(insertDate) withObject:nil afterDelay:3.0];  
    3.     }];  

    5.自定义显示的文字

    1. [_tableView.pullToRefreshView setTitle:@"下拉以刷新" forState:SVPullToRefreshStateTriggered];  
    2. [_tableView.pullToRefreshView setTitle:@"刷新完了呀" forState:SVPullToRefreshStateStopped];  
    3. [_tableView.pullToRefreshView setTitle:@"不要命的加载中..." forState:SVPullToRefreshStateLoading];  


    6.自定义刷新时的动画

    1. UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];  
    2. view.backgroundColor = [UIColor blueColor];  
    3. [UIView beginAnimations:nil context:nil];  
    4. [UIView setAnimationDuration:3];  
    5. view.alpha = 0.5 ;  
    6. [UIView commitAnimations];  
    7. [_tableView.pullToRefreshView setCustomView:view forState:SVPullToRefreshStateAll];  


    当然可以把view换成imageView等控件实现动画效果
    7.实现刷新和加载的两个方法

     

     

    1. - (void)refreshTableView  
    2. {  
    3. }  
    4. - (void)insertDate  
    5. {  
    6. }  


     

    三.注意事项

    iOS7和我们的下拉刷新库有冲突,因为都是对contentOffset进行操作,解决冲突,有两种做法

     

    方法1:禁用navgationbar的半透明效果,还原至iOS6中的效果

       

    1. self.navigationController.navigationBar.translucent = NO;  


    方法2:禁止系统自己修改contentOffset,然后修改tableView的frame

    automaticallyAdjustsScrollViewInsets 这个属性,只有iOS7以后才能用,所以如果要兼容iOS6,在iOS6运行,我们需要判断一下能不能使用这个属性或者当前的系统版本

    最终代码为:

    1. if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)   
      1. {  
      2.     self.automaticallyAdjustsScrollViewInsets = NO;  
      3.       
      4.     _tableView.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height - 64);  
      5. }; 
  • 相关阅读:
    shiro登录验证原理
    注解 java.lang.annotation.Inherited 介绍
    Spring Boot默认Initializer(1)——ConfigurationWarningsApplicationContextInitializer
    Java的static类
    Spring Boot中的initializers的作用分析
    2. Spring Boot项目启动原理初探
    1.Spring Boot入门及其jar包依赖模型分析
    关于正则式中的 |
    iOS :ViewDidAppear
    Xcode
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5405486.html
Copyright © 2020-2023  润新知