MJRefreshComponent.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /** 刷新控件的状态 */
  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);
  30. /** 开始刷新后的回调(进入刷新状态后的回调) */
  31. typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(void);
  32. /** 结束刷新后的回调 */
  33. typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void);
  34. /** 刷新控件的基类 */
  35. @interface MJRefreshComponent : UIView
  36. {
  37. /** 记录scrollView刚开始的inset */
  38. UIEdgeInsets _scrollViewOriginalInset;
  39. /** 父控件 */
  40. __weak UIScrollView *_scrollView;
  41. }
  42. #pragma mark - 刷新回调
  43. /** 正在刷新的回调 */
  44. @property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock;
  45. /** 设置回调对象和回调方法 */
  46. - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action;
  47. /** 回调对象 */
  48. @property (weak, nonatomic) id refreshingTarget;
  49. /** 回调方法 */
  50. @property (assign, nonatomic) SEL refreshingAction;
  51. /** 触发回调(交给子类去调用) */
  52. - (void)executeRefreshingCallback;
  53. #pragma mark - 刷新状态控制
  54. /** 进入刷新状态 */
  55. - (void)beginRefreshing;
  56. - (void)beginRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
  57. /** 开始刷新后的回调(进入刷新状态后的回调) */
  58. @property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock;
  59. /** 结束刷新的回调 */
  60. @property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock;
  61. /** 结束刷新状态 */
  62. - (void)endRefreshing;
  63. - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
  64. /** 是否正在刷新 */
  65. @property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing;
  66. //- (BOOL)isRefreshing;
  67. /** 刷新状态 一般交给子类内部实现 */
  68. @property (assign, nonatomic) MJRefreshState state;
  69. #pragma mark - 交给子类去访问
  70. /** 记录scrollView刚开始的inset */
  71. @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset;
  72. /** 父控件 */
  73. @property (weak, nonatomic, readonly) UIScrollView *scrollView;
  74. #pragma mark - 交给子类们去实现
  75. /** 初始化 */
  76. - (void)prepare NS_REQUIRES_SUPER;
  77. /** 摆放子控件frame */
  78. - (void)placeSubviews NS_REQUIRES_SUPER;
  79. /** 当scrollView的contentOffset发生改变的时候调用 */
  80. - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
  81. /** 当scrollView的contentSize发生改变的时候调用 */
  82. - (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
  83. /** 当scrollView的拖拽状态发生改变的时候调用 */
  84. - (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
  85. #pragma mark - 其他
  86. /** 拉拽的百分比(交给子类重写) */
  87. @property (assign, nonatomic) CGFloat pullingPercent;
  88. /** 根据拖拽比例自动切换透明度 */
  89. @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性");
  90. /** 根据拖拽比例自动切换透明度 */
  91. @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
  92. /// <#Description#>
  93. -(void)aspectsEndRefreshing:(void (^)(void))block;
  94. @end
  95. @interface UILabel(MJRefresh)
  96. + (instancetype)mj_label;
  97. - (CGFloat)mj_textWith;
  98. @end