全部产品

上拉刷新控件

更新时间:2019-09-26 18:39:57

  • 需要对 iOS 中的 BeeViews:BEESmilePullRefreshView(BEESmileAnimationView、BEESmileStaticView) 首页单独刷新控件,由首页负责。
  • 以下非业务定制化的控件,都需要切换为下拉(AUPullLoadingView)或上拉(AUDragLoadingView)组件。

    CommonUI:ODRefreshControl、APCircleRefreshControl、EGORefreshTableHeaderView、APNextPagePullView

效果图

接口说明

  • AUDragLoadingView.h

    1. //
    2. // AUDragLoadingView.h
    3. // AntUI
    4. //
    5. #import <AntUI/AntUI.h>
    6. @interface AUDragLoadingView : AUPullLoadingView
    7. @end
  • AUPullLoadingView.h

    下拉刷新控件

代码示例

  1. //
  2. // APRefreshTableViewController.m
  3. // UIDemo
  4. //
  5. #import "APRefreshTableViewController.h"
  6. @interface APRefreshTableViewController ()
  7. {
  8. BOOL _headerReloading;
  9. BOOL _footerReloading;
  10. BOOL _isHeader;
  11. }
  12. @property(nonatomic,strong)AUPullLoadingView *refreshHeaderView;
  13. @property(nonatomic,strong)AUDragLoadingView *refreshFooterView;
  14. @property(nonatomic, strong) UITableView *tableView;
  15. @property(nonatomic, strong) NSMutableArray* listArray;
  16. @end
  17. @implementation APRefreshTableViewController
  18. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  19. {
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. // Custom initialization
  23. NSArray *array = @[@"0",
  24. @"1",
  25. @"2",
  26. @"3",
  27. @"4",
  28. @"5",
  29. @"6",
  30. @"7",
  31. @"8",
  32. @"9",
  33. @"10",
  34. @"11",
  35. @"12",
  36. @"13",
  37. @"14",
  38. @"15",
  39. @"16",
  40. @"17",
  41. @"18",
  42. @"19"];
  43. self.listArray = [NSMutableArray arrayWithArray:array];
  44. }
  45. return self;
  46. }
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. // Do any additional setup after loading the view.
  51. self.edgesForExtendedLayout = UIRectEdgeNone;
  52. // self.navigationItem.rightBarButtonItem = [APUtil getBarButtonWithTitle:RightBarButtonTitle target:self];
  53. self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
  54. self.tableView.dataSource = self;
  55. self.tableView.delegate = self;
  56. self.tableView.backgroundColor = [UIColor colorWithRGB:0xf5f5f9];
  57. self.tableView.separatorColor = [UIColor colorWithRGB:0xdddddd];
  58. [self.view addSubview:self.tableView];
  59. if (_refreshHeaderView == nil) {
  60. AUPullLoadingView *view = [[AUPullLoadingView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
  61. view.delegate = self;
  62. [view ShowLastPullDate:YES];
  63. [view ShowStatusLabel:NO];
  64. [self.tableView addSubview:view];
  65. _refreshHeaderView = view;
  66. }
  67. [_refreshHeaderView refreshLastUpdatedDate];
  68. if (_refreshFooterView == nil) {
  69. AUDragLoadingView *view = [[AUDragLoadingView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 48)];
  70. view.delegate = self;
  71. [view setPullUp:@"上拉加载更多信息"];
  72. [view setRelease:@"放松"];
  73. self.tableView.tableFooterView = view;
  74. _refreshFooterView = view;
  75. }
  76. _isHeader = YES;
  77. }
  78. - (void)didReceiveMemoryWarning
  79. {
  80. [super didReceiveMemoryWarning];
  81. // Dispose of any resources that can be recreated.
  82. }
  83. #pragma tableview datasource
  84. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  85. {
  86. return 1;
  87. }
  88. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  89. {
  90. return _listArray.count;
  91. }
  92. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. static NSString *CellIdentifier = @"RefreshCell";
  95. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  96. if (nil == cell)
  97. {
  98. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  99. reuseIdentifier:CellIdentifier];
  100. }
  101. cell.textLabel.text = _listArray[indexPath.row];
  102. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  103. return cell;
  104. }
  105. #pragma mark -
  106. #pragma mark Data Source Loading / Reloading Methods
  107. - (void)reloadHeaderTableViewDataSource{
  108. // should be calling your tableviews data source model to reload
  109. // put here just for demo
  110. NSInteger first = [_listArray[0] integerValue] - 1;
  111. [_listArray insertObject:[NSString stringWithFormat:@"%li",(long)first] atIndex:0];
  112. _headerReloading = YES;
  113. }
  114. - (void)doneLoadingHeaderTableViewData{
  115. // model should call this when its done loading
  116. _headerReloading = NO;
  117. [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
  118. [self.tableView reloadData];
  119. }
  120. - (void)reloadFooterTableViewDataSource{
  121. // should be calling your tableviews data source model to reload
  122. // put here just for demo
  123. NSInteger count = [_listArray count];
  124. NSInteger last = [_listArray[count-1] integerValue] + 1;
  125. [_listArray addObject:[NSString stringWithFormat:@"%li",(long)last]];
  126. _footerReloading = YES;
  127. }
  128. - (void)doneLoadingFooterTableViewData{
  129. // model should call this when its done loading
  130. _footerReloading = NO;
  131. [_refreshFooterView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
  132. [self.tableView reloadData];
  133. }
  134. #pragma mark -
  135. #pragma mark UIScrollViewDelegate Methods
  136. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  137. {
  138. if (scrollView.contentInset.top + scrollView.contentOffset.y < 0) {
  139. _isHeader = YES;
  140. } else {
  141. _isHeader = NO;
  142. }
  143. if (_isHeader) {
  144. [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
  145. } else {
  146. [_refreshFooterView egoRefreshScrollViewDidScroll:scrollView];
  147. }
  148. }
  149. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  150. {
  151. if (_isHeader) {
  152. [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
  153. } else {
  154. [_refreshFooterView egoRefreshScrollViewDidEndDragging:scrollView];
  155. }
  156. }
  157. #pragma mark -
  158. #pragma mark EGORefreshTableHeaderDelegate Methods
  159. - (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view
  160. {
  161. if (_isHeader) {
  162. [self reloadHeaderTableViewDataSource];
  163. [self performSelector:@selector(doneLoadingHeaderTableViewData) withObject:nil afterDelay:2.0];
  164. } else {
  165. [self reloadFooterTableViewDataSource];
  166. [self performSelector:@selector(doneLoadingFooterTableViewData) withObject:nil afterDelay:2.0];
  167. }
  168. }
  169. - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view
  170. {
  171. if (_isHeader) {
  172. return _headerReloading;
  173. } else {
  174. return _footerReloading; // should return if data source model is reloading
  175. }
  176. }
  177. - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view{
  178. return [NSDate date]; // should return date data source was last changed
  179. }
  180. @end