一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。
OC Control NewPagedFlowView(卡片轮播器)下载链接
今天是2021年春节 初一 祝大家春节快乐
效果
提供的属性和方法
/**
* 默认为横向
*/
@property (nonatomic,assign) FHXNewPagedFlowViewOrientation orientation;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic,assign) BOOL needsReload;
/**
* 总页数
*/
@property (nonatomic,assign) NSInteger pageCount;
@property (nonatomic,strong) NSMutableArray *cells;
@property (nonatomic,assign) NSRange visibleRange;
/**
* 如果以后需要支持reuseIdentifier,这边就得使用字典类型了
*/
@property (nonatomic,strong) NSMutableArray *reusableCells;
@property (nonatomic,assign) id <FHXNewPagedFlowViewDataSource> dataSource;
@property (nonatomic,assign) id <FHXNewPagedFlowViewDelegate> delegate;
/**
* 指示器
*/
@property (nonatomic,retain) UIPageControl *pageControl;
/**
* 非当前页的透明比例
*/
@property (nonatomic, assign) CGFloat minimumPageAlpha;
/**
左右间距,默认20
*/
@property (nonatomic, assign) CGFloat leftRightMargin;
/**
上下间距,默认30
*/
@property (nonatomic, assign) CGFloat topBottomMargin;
/**
* 是否开启自动滚动,默认为开启
*/
@property (nonatomic, assign) BOOL isOpenAutoScroll;
/**
* 是否开启无限轮播,默认为开启
*/
@property (nonatomic, assign) BOOL isCarousel;
/**
* 当前是第几页
*/
@property (nonatomic, assign, readonly) NSInteger currentPageIndex;
/**
* 定时器
*/
@property (nonatomic, weak) NSTimer *timer;
/**
* 自动切换视图的时间,默认是5.0
*/
@property (nonatomic, assign) CGFloat autoTime;
/**
* 原始页数
*/
@property (nonatomic, assign) NSInteger orginPageCount;
/**
* 刷新视图
*/
- (void)reloadData;
/**
* 获取可重复使用的Cell
*
* @return <#return value description#>
*/
- (FHXIndexBannerSubiew *)dequeueReusableCell;
/**
* 滚动到指定的页面
*
* @param pageNumber <#pageNumber description#>
*/
- (void)scrollToPage:(NSUInteger)pageNumber;
/**
* 开启定时器,废弃
*/
//- (void)startTimer;
/**
* 关闭定时器,关闭自动滚动
*/
- (void)stopTimer;
/**
调整中间页居中,经常出现滚动卡住一半时调用
*/
- (void)adjustCenterSubview;
@end
@protocol FHXNewPagedFlowViewDelegate<NSObject>
@optional
/**
* 当前显示cell的Size(中间页显示大小)
*
* @param flowView <#flowView description#>
*
* @return <#return value description#>
*/
- (CGSize)sizeForPageInFlowView:(FHXNewPagedFlowView *)flowView;
/**
* 滚动到了某一列
*
* @param pageNumber <#pageNumber description#>
* @param flowView <#flowView description#>
*/
- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(FHXNewPagedFlowView *)flowView;
/**
* 点击了第几个cell
*
* @param subView 点击的控件
* @param subIndex 点击控件的index
*
* @return <#return value description#>
*/
- (void)didSelectCell:(FHXIndexBannerSubiew *)subView withSubViewIndex:(NSInteger)subIndex;
使用
<FHXNewPagedFlowViewDelegate, FHXNewPagedFlowViewDataSource>
@property (nonatomic, strong) NSArray *imageArray;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.imageArray = @[@"Yosemite00",@"Yosemite01",@"Yosemite02",@"Yosemite03",@"Yosemite04"];
FHXNewPagedFlowView *pageFlowView = [[FHXNewPagedFlowView alloc] initWithFrame:CGRectMake(0, 8, Phone_Width, Phone_Width * 9 / 16)];
pageFlowView.delegate = self;
pageFlowView.dataSource = self;
//非当前页的透明比例
pageFlowView.minimumPageAlpha = 0.1;
//是否开启无限轮播,默认为开启
pageFlowView.isCarousel = YES;
//默认为横向
pageFlowView.orientation = FHXNewPagedFlowViewOrientationHorizontal;
//是否开启自动滚动, 默认开启
pageFlowView.isOpenAutoScroll = YES;
//左右间距
pageFlowView.leftRightMargin = 40;
//上下间距
pageFlowView.topBottomMargin = 60;
//自动切换视图的时间,默认是5.0
pageFlowView.autoTime = 1;
/****************************
使用导航控制器(UINavigationController)
如果控制器中不存在UIScrollView或者继承自UIScrollView的UI控件
请使用UIScrollView作为NewPagedFlowView的容器View,才会显示正常,如下
*****************************/
UIScrollView *bottomScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[bottomScrollView addSubview:pageFlowView];
[self.view addSubview:bottomScrollView];
[pageFlowView reloadData];
}
#pragma mark NewPagedFlowView Delegate
- (CGSize)sizeForPageInFlowView:(FHXNewPagedFlowView *)flowView {
return CGSizeMake(Phone_Width - 60, (Phone_Width - 60) * 9 / 16);
}
- (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
NSLog(@"点击了第%ld张图",(long)subIndex + 1);
}
#pragma mark NewPagedFlowView Datasource
- (NSInteger)numberOfPagesInFlowView:(FHXNewPagedFlowView *)flowView {
return self.imageArray.count;
}
- (UIView *)flowView:(FHXNewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
FHXIndexBannerSubiew *bannerView = (FHXIndexBannerSubiew *)[flowView dequeueReusableCell];
if (!bannerView) {
bannerView = [[FHXIndexBannerSubiew alloc] initWithFrame:CGRectMake(0, 0, Phone_Width, Phone_Width * 9 / 16)];
bannerView.tag = index;
bannerView.layer.cornerRadius = 4;
bannerView.layer.masksToBounds = YES;
}
//在这里下载网络图片
// [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:hostUrlsImg,imageDict[@"img"]]] placeholderImage:[UIImage imageNamed:@""]];
bannerView.mainImageView.image = [UIImage imageNamed:self.imageArray[index]];
return bannerView;
}
- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(FHXNewPagedFlowView *)flowView {
NSLog(@"ViewController 滚动到了第%ld页",pageNumber);
}