MJRefreshComponent.h 4.4 KB

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