123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // TYCyclePagerView.h
- // TYCyclePagerViewDemo
- //
- // Created by tany on 2017/6/14.
- // Copyright © 2017年 tany. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "TYCyclePagerTransformLayout.h"
- #import "TYPageControl.h"
- //#if __has_include(<TYCyclePagerView/TYCyclePagerView.h>)
- //#import <TYCyclePagerView/TYCyclePagerTransformLayout.h>
- //#else
- //#import "TYCyclePagerTransformLayout.h"
- //#endif
- //#if __has_include(<TYCyclePagerView/TYPageControl.h>)
- //#import <TYCyclePagerView/TYPageControl.h>
- //#endif
- NS_ASSUME_NONNULL_BEGIN
- typedef struct {
- NSInteger index;
- NSInteger section;
- }TYIndexSection;
- // pagerView scrolling direction
- typedef NS_ENUM(NSUInteger, TYPagerScrollDirection) {
- TYPagerScrollDirectionLeft,
- TYPagerScrollDirectionRight,
- };
- @class TYCyclePagerView;
- @protocol TYCyclePagerViewDataSource <NSObject>
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView;
- - (__kindof UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index;
- /**
- return pagerView layout,and cache layout
- */
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView;
- @end
- @protocol TYCyclePagerViewDelegate <NSObject>
- @optional
- /**
- pagerView did scroll to new index page
- */
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;
- /**
- pagerView did selected item cell
- */
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index;
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndexSection:(TYIndexSection)indexSection;
- // custom layout
- - (void)pagerView:(TYCyclePagerView *)pageView initializeTransformAttributes:(UICollectionViewLayoutAttributes *)attributes;
- - (void)pagerView:(TYCyclePagerView *)pageView applyTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes;
- // scrollViewDelegate
- - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView;
- - (void)pagerViewWillBeginDragging:(TYCyclePagerView *)pageView;
- - (void)pagerViewDidEndDragging:(TYCyclePagerView *)pageView willDecelerate:(BOOL)decelerate;
- - (void)pagerViewWillBeginDecelerating:(TYCyclePagerView *)pageView;
- - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView;
- - (void)pagerViewWillBeginScrollingAnimation:(TYCyclePagerView *)pageView;
- - (void)pagerViewDidEndScrollingAnimation:(TYCyclePagerView *)pageView;
- @end
- @interface TYCyclePagerView : UIView
- // will be automatically resized to track the size of the pagerView
- @property (nonatomic, strong, nullable) UIView *backgroundView;
- @property (nonatomic, weak, nullable) id<TYCyclePagerViewDataSource> dataSource;
- @property (nonatomic, weak, nullable) id<TYCyclePagerViewDelegate> delegate;
- // pager view, don't set dataSource and delegate
- @property (nonatomic, weak, readonly) UICollectionView *collectionView;
- // pager view layout
- @property (nonatomic, strong, readonly) TYCyclePagerViewLayout *layout;
- /**
- is infinite cycle pageview
- */
- @property (nonatomic, assign) BOOL isInfiniteLoop;
- /**
- pagerView automatic scroll time interval, default 0,disable automatic
- */
- @property (nonatomic, assign) CGFloat autoScrollInterval;
- @property (nonatomic, assign) BOOL reloadDataNeedResetIndex;
- /**
- current page index
- */
- @property (nonatomic, assign, readonly) NSInteger curIndex;
- @property (nonatomic, assign, readonly) TYIndexSection indexSection;
- // scrollView property
- @property (nonatomic, assign, readonly) CGPoint contentOffset;
- @property (nonatomic, assign, readonly) BOOL tracking;
- @property (nonatomic, assign, readonly) BOOL dragging;
- @property (nonatomic, assign, readonly) BOOL decelerating;
- /**
- reload data, !!important!!: will clear layout and call delegate layoutForPagerView
- */
- - (void)reloadData;
- /**
- update data is reload data, but not clear layuot
- */
- - (void)updateData;
- /**
- if you only want update layout
- */
- - (void)setNeedUpdateLayout;
- /**
- will set layout nil and call delegate->layoutForPagerView
- */
- - (void)setNeedClearLayout;
- /**
- current index cell in pagerView
- */
- - (__kindof UICollectionViewCell * _Nullable)curIndexCell;
- /**
- visible cells in pageView
- */
- - (NSArray<__kindof UICollectionViewCell *> *_Nullable)visibleCells;
- /**
- visible pageView indexs, maybe repeat index
- */
- - (NSArray *)visibleIndexs;
- /**
- scroll to item at index
- */
- - (void)scrollToItemAtIndex:(NSInteger)index animate:(BOOL)animate;
- - (void)scrollToItemAtIndexSection:(TYIndexSection)indexSection animate:(BOOL)animate;
- /**
- scroll to next or pre item
- */
- - (void)scrollToNearlyIndexAtDirection:(TYPagerScrollDirection)direction animate:(BOOL)animate;
- /**
- register pager view cell with class
- */
- - (void)registerClass:(Class)Class forCellWithReuseIdentifier:(NSString *)identifier;
- /**
- register pager view cell with nib
- */
- - (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
- /**
- dequeue reusable cell for pagerView
- */
- - (__kindof UICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
- @end
- NS_ASSUME_NONNULL_END
|