线上所有马甲包模板,与《猎豆》同UI。域名zhuadd

UICollectionView+MJRefreshAutoManger.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // UICollectionView+MJRefreshAutoManger.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "UICollectionView+MJRefreshAutoManger.h"
  9. #define NO_MORE_DATA_TEXT @"无更多数据了"
  10. @implementation UICollectionView (MJRefreshAutoManger)
  11. static char stateKey;
  12. - (void)setFootRefreshState:(MJFooterRefreshState)footRefreshState {
  13. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  14. [RACObserve(self.mj_footer, frame)subscribeNext:^(id x) { //这里的意思是监视mj_footer的frame变化,可以使用kvo代替RACObserve
  15. CGPoint point = [self convertPoint:self.mj_footer.frame.origin toView:window];
  16. if (point.y < window.frame.size.height) {
  17. [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"" forState:MJRefreshStateIdle];
  18. }else {
  19. [(MJRefreshAutoNormalFooter *)self.mj_footer setTitle:@"点击或上拉加载更多" forState:MJRefreshStateIdle];
  20. [(MJRefreshAutoNormalFooter *)self.mj_footer resetNoMoreData];
  21. }
  22. }];
  23. [self handleFooterRefresh:footRefreshState];
  24. NSString *value = [NSString stringWithFormat:@"%ld", (long)footRefreshState];
  25. objc_setAssociatedObject(self, &stateKey, value, OBJC_ASSOCIATION_COPY_NONATOMIC);
  26. }
  27. - (MJFooterRefreshState)footRefreshState {
  28. NSString *refreshState = objc_getAssociatedObject(self, &stateKey);
  29. if ([refreshState isEqualToString:@"MJFooterRefreshStateLoadMore"]) {
  30. return MJFooterRefreshStateNoMore;
  31. }
  32. else {
  33. return MJFooterRefreshStateLoadMore;
  34. }
  35. }
  36. - (void)handleFooterRefresh: (MJFooterRefreshState)footRefreshState {
  37. MJRefreshAutoNormalFooter *footer = (MJRefreshAutoNormalFooter*)self.mj_footer;
  38. switch (footRefreshState) {
  39. case MJFooterRefreshStateNormal:
  40. {
  41. [footer setTitle:@"" forState:MJRefreshStateIdle];
  42. break;
  43. }
  44. case MJFooterRefreshStateLoadMore:
  45. {
  46. [self.mj_footer endRefreshing];
  47. break;
  48. }
  49. case MJFooterRefreshStateNoMore:
  50. {
  51. [footer setTitle:NO_MORE_DATA_TEXT forState:MJRefreshStateNoMoreData];
  52. [self.mj_footer endRefreshingWithNoMoreData];
  53. break;
  54. }
  55. default:
  56. break;
  57. }
  58. }
  59. @end