TYCyclePagerView.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // TYCyclePagerView.h
  3. // TYCyclePagerViewDemo
  4. //
  5. // Created by tany on 2017/6/14.
  6. // Copyright © 2017年 tany. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "TYCyclePagerTransformLayout.h"
  10. #import "TYPageControl.h"
  11. //#if __has_include(<TYCyclePagerView/TYCyclePagerView.h>)
  12. //#import <TYCyclePagerView/TYCyclePagerTransformLayout.h>
  13. //#else
  14. //#import "TYCyclePagerTransformLayout.h"
  15. //#endif
  16. //#if __has_include(<TYCyclePagerView/TYPageControl.h>)
  17. //#import <TYCyclePagerView/TYPageControl.h>
  18. //#endif
  19. NS_ASSUME_NONNULL_BEGIN
  20. typedef struct {
  21. NSInteger index;
  22. NSInteger section;
  23. }TYIndexSection;
  24. // pagerView scrolling direction
  25. typedef NS_ENUM(NSUInteger, TYPagerScrollDirection) {
  26. TYPagerScrollDirectionLeft,
  27. TYPagerScrollDirectionRight,
  28. };
  29. @class TYCyclePagerView;
  30. @protocol TYCyclePagerViewDataSource <NSObject>
  31. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView;
  32. - (__kindof UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index;
  33. /**
  34. return pagerView layout,and cache layout
  35. */
  36. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView;
  37. @end
  38. @protocol TYCyclePagerViewDelegate <NSObject>
  39. @optional
  40. /**
  41. pagerView did scroll to new index page
  42. */
  43. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;
  44. /**
  45. pagerView did selected item cell
  46. */
  47. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index;
  48. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndexSection:(TYIndexSection)indexSection;
  49. // custom layout
  50. - (void)pagerView:(TYCyclePagerView *)pageView initializeTransformAttributes:(UICollectionViewLayoutAttributes *)attributes;
  51. - (void)pagerView:(TYCyclePagerView *)pageView applyTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes;
  52. // scrollViewDelegate
  53. - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView;
  54. - (void)pagerViewWillBeginDragging:(TYCyclePagerView *)pageView;
  55. - (void)pagerViewDidEndDragging:(TYCyclePagerView *)pageView willDecelerate:(BOOL)decelerate;
  56. - (void)pagerViewWillBeginDecelerating:(TYCyclePagerView *)pageView;
  57. - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView;
  58. - (void)pagerViewWillBeginScrollingAnimation:(TYCyclePagerView *)pageView;
  59. - (void)pagerViewDidEndScrollingAnimation:(TYCyclePagerView *)pageView;
  60. @end
  61. @interface TYCyclePagerView : UIView
  62. // will be automatically resized to track the size of the pagerView
  63. @property (nonatomic, strong, nullable) UIView *backgroundView;
  64. @property (nonatomic, weak, nullable) id<TYCyclePagerViewDataSource> dataSource;
  65. @property (nonatomic, weak, nullable) id<TYCyclePagerViewDelegate> delegate;
  66. // pager view, don't set dataSource and delegate
  67. @property (nonatomic, weak, readonly) UICollectionView *collectionView;
  68. // pager view layout
  69. @property (nonatomic, strong, readonly) TYCyclePagerViewLayout *layout;
  70. /**
  71. is infinite cycle pageview
  72. */
  73. @property (nonatomic, assign) BOOL isInfiniteLoop;
  74. /**
  75. pagerView automatic scroll time interval, default 0,disable automatic
  76. */
  77. @property (nonatomic, assign) CGFloat autoScrollInterval;
  78. @property (nonatomic, assign) BOOL reloadDataNeedResetIndex;
  79. /**
  80. current page index
  81. */
  82. @property (nonatomic, assign, readonly) NSInteger curIndex;
  83. @property (nonatomic, assign, readonly) TYIndexSection indexSection;
  84. // scrollView property
  85. @property (nonatomic, assign, readonly) CGPoint contentOffset;
  86. @property (nonatomic, assign, readonly) BOOL tracking;
  87. @property (nonatomic, assign, readonly) BOOL dragging;
  88. @property (nonatomic, assign, readonly) BOOL decelerating;
  89. /**
  90. reload data, !!important!!: will clear layout and call delegate layoutForPagerView
  91. */
  92. - (void)reloadData;
  93. /**
  94. update data is reload data, but not clear layuot
  95. */
  96. - (void)updateData;
  97. /**
  98. if you only want update layout
  99. */
  100. - (void)setNeedUpdateLayout;
  101. /**
  102. will set layout nil and call delegate->layoutForPagerView
  103. */
  104. - (void)setNeedClearLayout;
  105. /**
  106. current index cell in pagerView
  107. */
  108. - (__kindof UICollectionViewCell * _Nullable)curIndexCell;
  109. /**
  110. visible cells in pageView
  111. */
  112. - (NSArray<__kindof UICollectionViewCell *> *_Nullable)visibleCells;
  113. /**
  114. visible pageView indexs, maybe repeat index
  115. */
  116. - (NSArray *)visibleIndexs;
  117. /**
  118. scroll to item at index
  119. */
  120. - (void)scrollToItemAtIndex:(NSInteger)index animate:(BOOL)animate;
  121. - (void)scrollToItemAtIndexSection:(TYIndexSection)indexSection animate:(BOOL)animate;
  122. /**
  123. scroll to next or pre item
  124. */
  125. - (void)scrollToNearlyIndexAtDirection:(TYPagerScrollDirection)direction animate:(BOOL)animate;
  126. /**
  127. register pager view cell with class
  128. */
  129. - (void)registerClass:(Class)Class forCellWithReuseIdentifier:(NSString *)identifier;
  130. /**
  131. register pager view cell with nib
  132. */
  133. - (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
  134. /**
  135. dequeue reusable cell for pagerView
  136. */
  137. - (__kindof UICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
  138. @end
  139. NS_ASSUME_NONNULL_END