因項(xiàng)目需求,會(huì)碰見像下圖這樣混排的輪播圖,于是決定重寫一個(gè)可以自定義每個(gè)pageView的輪播圖,按照tableView的使用方法開始了造輪子,使用方法和tableView類似,同時(shí)支持重用pageView,橫向和縱向。

Snip20190629_99.png

image.png
1、使用方法
@property (nonatomic, assign) BOOL dragEnable; //default YES
@property (nonatomic, assign) CGFloat interval; //auto scroll time
@property (nonatomic, weak) id<HHRotateViewDelegate>delegate;
@property (nonatomic, weak) id<HHRotateViewDataSrouce>dataSource;
/** init method */
- (instancetype)initWithFrame:(CGRect)frame style:(HHRotateViewStyle)style;
/** must to register cell class */
- (void)registerClass:(Class)cellClass identifier:(NSString *)identifier;
/** need to dequeue cell class, support reuse cell */
- (__kindof HHRotateViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier index:(NSInteger)index;
/** reload cell it will call dataSource method */
- (void)reloadData;
2、數(shù)據(jù)源方法
/* must to implementation */
- (NSInteger)numberOfRowsInRotateView:(HHRotateView *)rotateView;
/* must to implementation call `dequeueReusableCellWithIdentifier` */
- (__kindof HHRotateViewCell *)rotateView:(HHRotateView *)rotateView cellForRowAtIndex:(NSInteger)index;
@optional
/* return a View like UIPageControl need to conform `HHRotateViewDelegate` */
- (__kindof UIView <HHRotateViewDelegate>*)viewForSupplementaryView:(HHRotateView *)rotateView;
/* return a layout object */
- (HHSupplementViewLayout *)layoutForSupplementaryView;
viewForSupplementaryView為獲取pageControl對(duì)象
HHSupplementViewLayout對(duì)象為存儲(chǔ)的pageControl的布局對(duì)象
- (HHSupplementViewLayout *)layoutForSupplementaryView
{
//距離底部10pt,中心x與父視圖對(duì)其
return HHSupplementViewLayout.new.bottom(-10).centX(0);
}
3、 效果圖

Untitled.gif