JXPagerView.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // JXPagerView.h
  3. // JXPagerView
  4. //
  5. // Created by jiaxin on 2018/8/27.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "JXPagerMainTableView.h"
  10. #import "JXPagerListContainerView.h"
  11. @class JXPagerView;
  12. @protocol JXPagerViewDelegate <NSObject>
  13. /**
  14. 返回tableHeaderView的高度,因为内部需要比对判断,只能是整型数
  15. */
  16. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView;
  17. /**
  18. 返回tableHeaderView
  19. */
  20. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView;
  21. /**
  22. 返回悬浮HeaderView的高度,因为内部需要比对判断,只能是整型数
  23. */
  24. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView;
  25. /**
  26. 返回悬浮HeaderView。我用的是自己封装的JXCategoryView(Github:https://github.com/pujiaxin33/JXCategoryView),你也可以选择其他的三方库或者自己写
  27. */
  28. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView;
  29. /**
  30. 返回列表的数量
  31. */
  32. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView;
  33. /**
  34. 根据index初始化一个对应列表实例,需要是遵从`JXPagerViewListViewDelegate`协议的对象。
  35. 如果列表是用自定义UIView封装的,就让自定义UIView遵从`JXPagerViewListViewDelegate`协议,该方法返回自定义UIView即可。
  36. 如果列表是用自定义UIViewController封装的,就让自定义UIViewController遵从`JXPagerViewListViewDelegate`协议,该方法返回自定义UIViewController即可。
  37. 注意:一定要是新生成的实例!!!
  38. @param pagerView pagerView description
  39. @param index index description
  40. @return 新生成的列表实例
  41. */
  42. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index;
  43. @optional
  44. /// 返回对应index的列表唯一标识
  45. /// @param pagerView pagerView description
  46. /// @param index index description
  47. - (NSString *)pagerView:(JXPagerView *)pagerView listIdentifierAtIndex:(NSInteger)index;
  48. - (void)mainTableViewDidScroll:(UIScrollView *)scrollView __attribute__ ((deprecated));
  49. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView;
  50. - (void)pagerView:(JXPagerView *)pagerView mainTableViewWillBeginDragging:(UIScrollView *)scrollView;
  51. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
  52. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidEndDecelerating:(UIScrollView *)scrollView;
  53. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
  54. /**
  55. 返回自定义UIScrollView或UICollectionView的Class
  56. 某些特殊情况需要自己处理列表容器内UIScrollView内部逻辑。比如项目用了FDFullscreenPopGesture,需要处理手势相关代理。
  57. @param pagerView JXPagerView
  58. @return 自定义UIScrollView实例
  59. */
  60. - (Class)scrollViewClassInlistContainerViewInPagerView:(JXPagerView *)pagerView;
  61. @end
  62. @interface JXPagerView : UIView
  63. /**
  64. 需要和self.categoryView.defaultSelectedIndex保持一致
  65. */
  66. @property (nonatomic, assign) NSInteger defaultSelectedIndex;
  67. @property (nonatomic, strong, readonly) JXPagerMainTableView *mainTableView;
  68. @property (nonatomic, strong, readonly) JXPagerListContainerView *listContainerView;
  69. /**
  70. 当前已经加载过可用的列表字典,key就是index值,value是对应的列表。
  71. */
  72. @property (nonatomic, strong, readonly) NSDictionary <NSNumber *, id<JXPagerViewListViewDelegate>> *validListDict;
  73. /**
  74. 顶部固定sectionHeader的垂直偏移量。数值越大越往下沉。
  75. */
  76. @property (nonatomic, assign) NSInteger pinSectionHeaderVerticalOffset;
  77. /**
  78. 是否允许列表左右滑动。默认:YES
  79. */
  80. @property (nonatomic, assign) BOOL isListHorizontalScrollEnabled;
  81. /**
  82. 是否允许当前列表自动显示或隐藏列表是垂直滚动指示器。YES:悬浮的headerView滚动到顶部开始滚动列表时,就会显示,反之隐藏。NO:内部不会处理列表的垂直滚动指示器。默认为:YES。
  83. */
  84. @property (nonatomic, assign) BOOL automaticallyDisplayListVerticalScrollIndicator;
  85. /**
  86. 当allowsCacheList为true时,请务必实现代理方法`- (NSString *)pagerView:(JXPagerView *)pagerView listIdentifierAtIndex:(NSInteger)index`
  87. */
  88. @property (nonatomic, assign) BOOL allowsCacheList;
  89. - (instancetype)initWithDelegate:(id<JXPagerViewDelegate>)delegate;
  90. - (instancetype)initWithDelegate:(id<JXPagerViewDelegate>)delegate listContainerType:(JXPagerListContainerType)type NS_DESIGNATED_INITIALIZER;
  91. - (instancetype)init NS_UNAVAILABLE;
  92. - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
  93. - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
  94. - (void)reloadData;
  95. - (void)resizeTableHeaderViewHeightWithAnimatable:(BOOL)animatable duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;
  96. @end
  97. /**
  98. 暴露给子类使用,请勿直接使用相关属性和方法!
  99. */
  100. @interface JXPagerView (UISubclassingGet)
  101. @property (nonatomic, strong, readonly) UIScrollView *currentScrollingListView;
  102. @property (nonatomic, strong, readonly) id<JXPagerViewListViewDelegate> currentList;
  103. @property (nonatomic, assign, readonly) CGFloat mainTableViewMaxContentOffsetY;
  104. @end
  105. @interface JXPagerView (UISubclassingHooks)
  106. - (void)preferredProcessListViewDidScroll:(UIScrollView *)scrollView;
  107. - (void)preferredProcessMainTableViewDidScroll:(UIScrollView *)scrollView;
  108. - (void)setMainTableViewToMaxContentOffsetY;
  109. - (void)setListScrollViewToMinContentOffsetY:(UIScrollView *)scrollView;
  110. - (CGFloat)minContentOffsetYInListScrollView:(UIScrollView *)scrollView;
  111. @end