MJRefreshComponent.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /** 刷新控件的状态 */
  14. typedef enum {
  15. /** 普通闲置状态 */
  16. MJRefreshStateIdle = 1,
  17. /** 松开就可以进行刷新的状态 */
  18. MJRefreshStatePulling,
  19. /** 正在刷新中的状态 */
  20. MJRefreshStateRefreshing,
  21. /** 即将刷新的状态 */
  22. MJRefreshStateWillRefresh,
  23. /** 所有数据加载完毕,没有更多的数据了 */
  24. MJRefreshStateNoMoreData
  25. } MJRefreshState;
  26. /** 进入刷新状态的回调 */
  27. typedef void (^MJRefreshComponentRefreshingBlock)();
  28. /** 刷新控件的基类 */
  29. @interface MJRefreshComponent : UIView
  30. {
  31. /** 记录scrollView刚开始的inset */
  32. UIEdgeInsets _scrollViewOriginalInset;
  33. /** 父控件 */
  34. __weak UIScrollView *_scrollView;
  35. }
  36. #pragma mark - 刷新回调
  37. /** 正在刷新的回调 */
  38. @property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock;
  39. /** 设置回调对象和回调方法 */
  40. - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action;
  41. /** 回调对象 */
  42. @property (weak, nonatomic) id refreshingTarget;
  43. /** 回调方法 */
  44. @property (assign, nonatomic) SEL refreshingAction;
  45. /** 触发回调(交给子类去调用) */
  46. - (void)executeRefreshingCallback;
  47. #pragma mark - 刷新状态控制
  48. /** 进入刷新状态 */
  49. - (void)beginRefreshing;
  50. /** 结束刷新状态 */
  51. - (void)endRefreshing;
  52. /** 是否正在刷新 */
  53. - (BOOL)isRefreshing;
  54. /** 刷新状态 一般交给子类内部实现 */
  55. @property (assign, nonatomic) MJRefreshState state;
  56. #pragma mark - 交给子类去访问
  57. /** 记录scrollView刚开始的inset */
  58. @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset;
  59. /** 父控件 */
  60. @property (weak, nonatomic, readonly) UIScrollView *scrollView;
  61. #pragma mark - 交给子类们去实现
  62. /** 初始化 */
  63. - (void)prepare;
  64. /** 摆放子控件frame */
  65. - (void)placeSubviews;
  66. /** 当scrollView的contentOffset发生改变的时候调用 */
  67. - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change;
  68. /** 当scrollView的contentSize发生改变的时候调用 */
  69. - (void)scrollViewContentSizeDidChange:(NSDictionary *)change;
  70. /** 当scrollView的contentInset发生改变的时候调用 */
  71. - (void)scrollViewContentInsetDidChange:(NSDictionary *)change;
  72. /** 当scrollView的拖拽状态发生改变的时候调用 */
  73. - (void)scrollViewPanStateDidChange:(NSDictionary *)change;
  74. #pragma mark - 其他
  75. /** 拉拽的百分比(交给子类重写) */
  76. @property (assign, nonatomic) CGFloat pullingPercent;
  77. /** 根据拖拽比例自动切换透明度 */
  78. @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性");
  79. /** 根据拖拽比例自动切换透明度 */
  80. @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
  81. @end
  82. @interface UILabel(MJRefresh)
  83. + (instancetype)label;
  84. @end