全部产品

下拉刷新控件

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

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

    CommonUI:ODRefreshControl、APCircleRefreshControl、EGORefreshTableHeaderView、APNextPagePullView

效果图

接口说明

  • AUPullLoadingView.h

    1. //
    2. // EGORefreshTableHeaderView.h
    3. // Demo
    4. //
    5. #import <UIKit/UIKit.h>
    6. #import <QuartzCore/QuartzCore.h>
    7. typedef enum {
    8. AUEGOPullingDown = 1000,
    9. AUEGOPullingUp
    10. } AUEGOPullDirection;
    11. typedef enum{
    12. AUEGOOPullRefreshPulling = 0,
    13. AUEGOOPullRefreshNormal,
    14. AUEGOOPullRefreshLoading,
    15. } AUEGOPullRefreshState;
    16. @class AULoadingIndicatorView;
    17. @protocol AURefreshLoadingViewDelegate;
    18. /*!
    19. @class AURefreshLoadingView
    20. @abstract UIView
    21. @discussion 从第三方 EGORefreshTableHeaderView 迁移而来,功能下拉、上拉加载更多的 view
    22. */
    23. @interface AUPullLoadingView : UIView {
    24. __weak id _delegate;
    25. AUEGOPullRefreshState _state;
    26. UILabel *_lastUpdatedLabel;
    27. UILabel *_statusLabel;
    28. // APActivityIndicatorView *_activityView;
    29. AUEGOPullDirection _pullDirection;
    30. BOOL isAutoPullFlag;
    31. }
    32. @property(nonatomic, strong) AULoadingIndicatorView *activityView;
    33. /**
    34. * 上拉加载时,设置初始状态文案信息,默认为“上拉加载更多”,显示
    35. *
    36. * @param tip tips内容
    37. *
    38. */
    39. - (void)setPullUp:(NSString *)tip;
    40. /**
    41. * 下拉刷新时,设置初始状态文案信息,默认为“下拉刷新”。不显示
    42. *
    43. * @param tip tips内容
    44. *
    45. */
    46. - (void)setPullDown:(NSString *)tip;
    47. /**
    48. * 设置松手后 loading 过程中的文案信息,默认为“加载中”。
    49. * 注意:默认下拉刷新时不显示,上拉加载时显示
    50. *
    51. * @param tip tips内容
    52. *
    53. */
    54. - (void)setLoading:(NSString *)tip;
    55. /**
    56. * 提示用户可以放手的文案信息,默认为“释放即可刷新”
    57. *
    58. * @param tip tips内容
    59. *
    60. */
    61. - (void)setRelease:(NSString *)tip;
    62. /**
    63. * 是否显示上次刷新信息的文案,默认不显示
    64. *
    65. * @param isOpen YES 表示显示
    66. *
    67. */
    68. - (void)ShowLastPullDate:(BOOL)isOpen;
    69. /**
    70. * 是否显示加载状态信息的文案。
    71. *
    72. * 默认:下拉刷新时不显示,上拉加载时,显示文案“加载中”
    73. *
    74. * @param isShow YES 表示显示
    75. *
    76. */
    77. - (void)ShowStatusLabel:(BOOL)isShow;
    78. - (void)setDateFormat:(NSDateFormatter *)dateFromatter;
    79. - (void)setAutoPull:(BOOL)isAutoPull;
    80. @property(nonatomic,weak) id <AURefreshLoadingViewDelegate> delegate;
    81. - (void)refreshLastUpdatedDate;
    82. - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView;
    83. - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView;
    84. - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView;
    85. - (void)egoRefreshScrollViewDataSourceDidFinishedLoadingWithoutUpdate:(UIScrollView *)scrollView;
    86. - (void)autoUpdateScrollView:(UIScrollView *)scrollView;
    87. #pragma Mark -- for LegacySystem not recommend
    88. @property(nonatomic,assign) AUEGOPullRefreshState state;
    89. @property(nonatomic,retain) NSString *statusText;
    90. @property (nonatomic, retain) UILabel *lastUpdatedLabel;
    91. @property (nonatomic, retain) UILabel *statusLabel;
    92. - (void)setCurrentDate;
    93. @end
    94. @protocol AURefreshLoadingViewDelegate
    95. - (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view;
    96. - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view;
    97. @optional
    98. - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view;
    99. @end
  • AUDragLoadingView.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