TYPagerView.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // TYPagerView.h
  3. // TYPagerControllerDemo
  4. //
  5. // Created by tany on 2017/7/5.
  6. // Copyright © 2017年 tanyang. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "TYPagerViewLayout.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class TYPagerView;
  12. @protocol TYPagerViewDataSource <NSObject>
  13. - (NSInteger)numberOfViewsInPagerView;
  14. /* 1.if prefetching is YES, the prefetch view not display.
  15. 2.if view will diaplay,will call willAppearView:forIndex:.
  16. 3.layout.frameForItemAtIndex can get view's frame
  17. 4.you can register && dequeue view, usage like tableView
  18. */
  19. - (UIView *)pagerView:(TYPagerView *)pagerView viewForIndex:(NSInteger)index prefetching:(BOOL)prefetching;
  20. @end
  21. @protocol TYPagerViewDelegate <NSObject>
  22. @optional
  23. // Display customization
  24. // if want do something in view will display,you can implement this
  25. - (void)pagerView:(TYPagerView *)pagerView willAppearView:(UIView *)view forIndex:(NSInteger)index;
  26. - (void)pagerView:(TYPagerView *)pagerView didAppearView:(UIView *)view forIndex:(NSInteger)index;
  27. // Disappear customization
  28. - (void)pagerView:(TYPagerView *)pagerView willDisappearView:(UIView *)view forIndex:(NSInteger)index;
  29. - (void)pagerView:(TYPagerView *)pagerView didDisappearView:(UIView *)view forIndex:(NSInteger)index;
  30. // Transition animation customization
  31. // if you implement ↓↓↓transitionFromIndex:toIndex:progress:,only tap change index will call this, you can set progressAnimateEnabel NO that not call progress method
  32. - (void)pagerView:(TYPagerView *)pagerView transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated;
  33. // if you implement the method,also you need implement ↑↑↑transitionFromIndex:toIndex:animated:,deal with tap change index animate
  34. - (void)pagerView:(TYPagerView *)pagerView transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;
  35. // scrollView delegate
  36. - (void)pagerViewDidScroll:(TYPagerView *)pageView;
  37. - (void)pagerViewWillBeginScrolling:(TYPagerView *)pageView animate:(BOOL)animate;
  38. - (void)pagerViewDidEndScrolling:(TYPagerView *)pageView animate:(BOOL)animate;
  39. @end
  40. @interface TYPagerView : UIView
  41. @property (nonatomic, weak, nullable) id<TYPagerViewDataSource> dataSource;
  42. @property (nonatomic, weak, nullable) id<TYPagerViewDelegate> delegate;
  43. // pagerView's layout,don't set layout's dataSource to other
  44. @property (nonatomic, strong, readonly) TYPagerViewLayout<UIView *> *layout;
  45. @property (nonatomic, strong, readonly) UIScrollView *scrollView;
  46. @property (nonatomic, assign, readonly) NSInteger countOfPagerViews;
  47. @property (nonatomic, assign, readonly) NSInteger curIndex;// default -1
  48. @property (nonatomic, assign, nullable, readonly) NSArray<UIView *> *visibleViews;
  49. @property (nonatomic, assign) UIEdgeInsets contentInset;
  50. //if not visible, prefecth, cache view at index, return nil
  51. - (UIView *_Nullable)viewForIndex:(NSInteger)index;
  52. // register && dequeue's usage like tableView
  53. - (void)registerClass:(Class)Class forViewWithReuseIdentifier:(NSString *)identifier;
  54. - (void)registerNib:(UINib *)nib forViewWithReuseIdentifier:(NSString *)identifier;
  55. - (UIView *)dequeueReusableViewWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
  56. // scroll to index
  57. - (void)scrollToViewAtIndex:(NSInteger)index animate:(BOOL)animate;
  58. // update data and layout,but don't reset propertys(curIndex,visibleDatas,prefechDatas)
  59. - (void)updateData;
  60. // reload data and reset propertys
  61. - (void)reloadData;
  62. @end
  63. NS_ASSUME_NONNULL_END