MJRefreshComponent.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // 代码地址: https://github.com/CoderMJLee/MJRefresh
  2. // MJRefreshComponent.h
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/3/4.
  6. // Copyright (c) 2015年 小码哥. All rights reserved.
  7. // 刷新控件的基类
  8. #import <UIKit/UIKit.h>
  9. #import "MJRefreshConst.h"
  10. #import "UIView+MJExtension.h"
  11. #import "UIScrollView+MJExtension.h"
  12. #import "UIScrollView+MJRefresh.h"
  13. #import "NSBundle+MJRefresh.h"
  14. NS_ASSUME_NONNULL_BEGIN
  15. /** 刷新控件的状态 */
  16. typedef NS_ENUM(NSInteger, MJRefreshState) {
  17. /** 普通闲置状态 */
  18. MJRefreshStateIdle = 1,
  19. /** 松开就可以进行刷新的状态 */
  20. MJRefreshStatePulling,
  21. /** 正在刷新中的状态 */
  22. MJRefreshStateRefreshing,
  23. /** 即将刷新的状态 */
  24. MJRefreshStateWillRefresh,
  25. /** 所有数据加载完毕,没有更多的数据了 */
  26. MJRefreshStateNoMoreData
  27. };
  28. /** 进入刷新状态的回调 */
  29. typedef void (^MJRefreshComponentRefreshingBlock)(void) MJRefreshDeprecated("first deprecated in 3.3.0 - Use `MJRefreshComponentAction` instead");
  30. /** 开始刷新后的回调(进入刷新状态后的回调) */
  31. typedef void (^MJRefreshComponentBeginRefreshingCompletionBlock)(void) MJRefreshDeprecated("first deprecated in 3.3.0 - Use `MJRefreshComponentAction` instead");
  32. /** 结束刷新后的回调 */
  33. typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void) MJRefreshDeprecated("first deprecated in 3.3.0 - Use `MJRefreshComponentAction` instead");
  34. /** 刷新用到的回调类型 */
  35. typedef void (^MJRefreshComponentAction)(void);
  36. /** 刷新控件的基类 */
  37. @interface MJRefreshComponent : UIView
  38. {
  39. /** 记录scrollView刚开始的inset */
  40. UIEdgeInsets _scrollViewOriginalInset;
  41. /** 父控件 */
  42. __weak UIScrollView *_scrollView;
  43. }
  44. #pragma mark - 刷新回调
  45. /** 正在刷新的回调 */
  46. @property (copy, nonatomic, nullable) MJRefreshComponentAction refreshingBlock;
  47. /** 设置回调对象和回调方法 */
  48. - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action;
  49. /** 回调对象 */
  50. @property (weak, nonatomic) id refreshingTarget;
  51. /** 回调方法 */
  52. @property (assign, nonatomic) SEL refreshingAction;
  53. /** 触发回调(交给子类去调用) */
  54. - (void)executeRefreshingCallback;
  55. #pragma mark - 刷新状态控制
  56. /** 进入刷新状态 */
  57. - (void)beginRefreshing;
  58. - (void)beginRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
  59. /** 开始刷新后的回调(进入刷新状态后的回调) */
  60. @property (copy, nonatomic, nullable) MJRefreshComponentAction beginRefreshingCompletionBlock;
  61. /** 带动画的结束刷新的回调 */
  62. @property (copy, nonatomic, nullable) MJRefreshComponentAction endRefreshingAnimateCompletionBlock MJRefreshDeprecated("first deprecated in 3.3.0 - Use `endRefreshingAnimationBeginAction` instead");
  63. @property (copy, nonatomic, nullable) MJRefreshComponentAction endRefreshingAnimationBeginAction;
  64. /** 结束刷新的回调 */
  65. @property (copy, nonatomic, nullable) MJRefreshComponentAction endRefreshingCompletionBlock;
  66. /** 结束刷新状态 */
  67. - (void)endRefreshing;
  68. - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
  69. /** 是否正在刷新 */
  70. @property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing;
  71. /** 刷新状态 一般交给子类内部实现 */
  72. @property (assign, nonatomic) MJRefreshState state;
  73. #pragma mark - 交给子类去访问
  74. /** 记录scrollView刚开始的inset */
  75. @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset;
  76. /** 父控件 */
  77. @property (weak, nonatomic, readonly) UIScrollView *scrollView;
  78. #pragma mark - 交给子类们去实现
  79. /** 初始化 */
  80. - (void)prepare NS_REQUIRES_SUPER;
  81. /** 摆放子控件frame */
  82. - (void)placeSubviews NS_REQUIRES_SUPER;
  83. /** 当scrollView的contentOffset发生改变的时候调用 */
  84. - (void)scrollViewContentOffsetDidChange:(nullable NSDictionary *)change NS_REQUIRES_SUPER;
  85. /** 当scrollView的contentSize发生改变的时候调用 */
  86. - (void)scrollViewContentSizeDidChange:(nullable NSDictionary *)change NS_REQUIRES_SUPER;
  87. /** 当scrollView的拖拽状态发生改变的时候调用 */
  88. - (void)scrollViewPanStateDidChange:(nullable NSDictionary *)change NS_REQUIRES_SUPER;
  89. #pragma mark - 其他
  90. /** 拉拽的百分比(交给子类重写) */
  91. @property (assign, nonatomic) CGFloat pullingPercent;
  92. /** 根据拖拽比例自动切换透明度 */
  93. @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性");
  94. /** 根据拖拽比例自动切换透明度 */
  95. @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
  96. @end
  97. @interface UILabel(MJRefresh)
  98. + (instancetype)mj_label;
  99. - (CGFloat)mj_textWidth;
  100. @end
  101. @interface MJRefreshComponent (ChainingGrammar)
  102. #pragma mark - <<< 为 Swift 扩展链式语法 >>> -
  103. /// 自动变化透明度
  104. - (instancetype)autoChangeTransparency:(BOOL)isAutoChange;
  105. /// 刷新开始后立即调用的回调
  106. - (instancetype)afterBeginningAction:(MJRefreshComponentAction)action;
  107. /// 刷新动画开始后立即调用的回调
  108. - (instancetype)endingAnimationBeginningAction:(MJRefreshComponentAction)action;
  109. /// 刷新结束后立即调用的回调
  110. - (instancetype)afterEndingAction:(MJRefreshComponentAction)action;
  111. /// 需要子类必须实现
  112. /// @param scrollView 赋值给的 ScrollView 的 Header/Footer/Trailer
  113. - (instancetype)assignTo:(UIScrollView *)scrollView;
  114. @end
  115. NS_ASSUME_NONNULL_END