Files
featherVoice/QXLive/HomePage(声播)/View/首页/GKCycleScrollView.h

144 lines
4.4 KiB
C
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// GKCycleScrollView.h
// GKCycleScrollViewDemo
//
// Created by QuintGao on 2019/9/15.
// Copyright © 2019 QuintGao. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "GKCycleScrollViewCell.h"
// 滚动方向
typedef NS_ENUM(NSUInteger, GKCycleScrollViewScrollDirection) {
GKCycleScrollViewScrollDirectionHorizontal = 0, // 横向
GKCycleScrollViewScrollDirectionVertical = 1 // 纵向
};
@class GKCycleScrollView;
/// 数据源代理
@protocol GKCycleScrollViewDataSource <NSObject>
/// 返回cell个数
/// @param cycleScrollView cycleScrollView description
- (NSInteger)numberOfCellsInCycleScrollView:(GKCycleScrollView *)cycleScrollView;
/// 返回继承自GKCycleScrollViewCell的类
/// @param cycleScrollView cycleScrollView description
/// @param index 索引
- (__kindof GKCycleScrollViewCell *)cycleScrollView:(GKCycleScrollView *)cycleScrollView cellForViewAtIndex:(NSInteger)index;
@end
@protocol GKCycleScrollViewDelegate <NSObject>
@optional
/// 返回自定义cell尺寸
/// @param cycleScrollView cycleScrollView description
- (CGSize)sizeForCellInCycleScrollView:(GKCycleScrollView *)cycleScrollView;
// cell滑动时调用
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didScrollCellToIndex:(NSInteger)index;
// cell点击时调用
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didSelectCellAtIndex:(NSInteger)index;
/// scrollView滚动中的回调
/// @param cycleScrollView cycleScrollView对象
/// @param fromIndex 正在滚动中相对位置处于左边或上边的index根据direction区分
/// @param toIndex 正在滚动中相对位置处于右边或下边的index根据direction区分
/// @param ratio 从左到右或从上到下计算的百分比根据direction区分
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView scrollingFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex ratio:(CGFloat)ratio;
#pragma mark - UIScrollViewDelegate 相关
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView willBeginDragging:(UIScrollView *)scrollView;
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didScroll:(UIScrollView *)scrollView;
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didEndDecelerating:(UIScrollView *)scrollView;
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didEndScrollingAnimation:(UIScrollView *)scrollView;
@end
@interface GKCycleScrollView : UIView
// 数据源
@property (nonatomic, weak) id<GKCycleScrollViewDataSource> dataSource;
// 代理
@property (nonatomic, weak) id<GKCycleScrollViewDelegate> delegate;
// 滚动方向,默认为横向
@property (nonatomic, assign) GKCycleScrollViewScrollDirection direction;
// 滚动视图
@property (nonatomic, strong, readonly) UIScrollView *scrollView;
// 默认为nil需外部创建并传入
@property (nonatomic, weak) UIPageControl *pageControl;
// 当前展示的cell
@property (nonatomic, strong, readonly) GKCycleScrollViewCell *currentCell;
// 当前显示的页码
@property (nonatomic, assign, readonly) NSInteger currentSelectIndex;
// 默认选中的页码默认0
@property (nonatomic, assign) NSInteger defaultSelectIndex;
// 是否自动滚动默认YES
@property (nonatomic, assign) BOOL isAutoScroll;
// 是否无限循环默认YES
@property (nonatomic, assign) BOOL isInfiniteLoop;
// 是否改变透明度默认YES
@property (nonatomic, assign) BOOL isChangeAlpha;
// 非当前页cell的最小透明度默认1.0f
@property (nonatomic, assign) CGFloat minimumCellAlpha;
// 左右间距默认0
@property (nonatomic, assign) CGFloat leftRightMargin;
// 上下间距默认0
@property (nonatomic, assign) CGFloat topBottomMargin;
// 自动滚动时间间隔默认3s
@property (nonatomic, assign) CGFloat autoScrollTime;
/**
*/
- (void)reloadData;
/**
使cell
@return cell
*/
- (GKCycleScrollViewCell *)dequeueReusableCell;
/**
cell
@param index cell的索引
@param animated
*/
- (void)scrollToCellAtIndex:(NSInteger)index animated:(BOOL)animated;
/**
cell的位置
*/
- (void)adjustCurrentCell;
/**
*/
- (void)startTimer;
/**
*/
- (void)stopTimer;
@end