SVPullToRefresh? 下拉重新整理,上拉載入

來源:互聯網
上載者:User

標籤:

一.下載第三方庫

https://github.com/samvermette/SVPullToRefresh

二.使用方法

1.匯入下載的第三方庫

2.匯入標頭檔

在需要的類裡匯入這一個標頭檔就能,同時使用下拉重新整理,上拉載入

#import "SVPullToRefresh.h"

 

3.下拉重新整理

[objc] view plain copy
  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.上拉載入

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

5.自訂顯示的文字

[objc] view plain copy
  1. [_tableView.pullToRefreshView setTitle:@"拖動以重新整理" forState:SVPullToRefreshStateTriggered];  
  2. [_tableView.pullToRefreshView setTitle:@"重新整理完了呀" forState:SVPullToRefreshStateStopped];  
  3. [_tableView.pullToRefreshView setTitle:@"不要命的載入中..." forState:SVPullToRefreshStateLoading];  


6.自訂重新整理時的動畫

[objc] view plain copy
  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.實現重新整理和載入的兩個方法

 

 

[objc] view plain copy
  1. - (void)refreshTableView  
  2. {  
  3. }  
  4. - (void)insertDate  
  5. {  
  6. }  


 

三.注意事項

iOS7和我們的下拉重新整理庫有衝突,因為都是對contentOffset進行操作,解決衝突,有兩種做法

 

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

   

[objc] view plain copy
  1. self.navigationController.navigationBar.translucent = NO;  


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

automaticallyAdjustsScrollViewInsets 這個屬性,只有iOS7以後才能用,所以如果要相容iOS6,在iOS6運行,我們需要判斷一下能不能使用這個屬性或者當前的系統版本

最終代碼為:

[objc] view plain copy
  1. if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)   
[objc] view plain copy
    1. {  
    2.     self.automaticallyAdjustsScrollViewInsets = NO;  
    3.       
    4.     _tableView.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height - 64);  
    5. }; 

SVPullToRefresh? 下拉重新整理,上拉載入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.