LXScrollContentView 一个类似网易新闻客户端左右滑动切换页面的框架

网友投稿 544 2022-11-04

LXScrollContentView 一个类似网易新闻客户端左右滑动切换页面的框架

LXScrollContentView 一个类似网易新闻客户端左右滑动切换页面的框架

LXScrollContentView

高仿网易新闻客户端左右滑动切换页面的框架

github链接:https://github.com/LiuXingCode/LXScrollContentView

简书链接:http://jianshu.com/p/4ca324102e10

swift版本链接:https://github.com/LiuXingCode/LXScollContentViewSwift

1. LXScrollContentView描述

2.安装方法

LXScrollContentView支持CocoaPods安装

pod 'LXScrollContentView'

也可以-示例Demo,把里面的LXScrollContentViewLib文件夹拖到你的项目中即可

3.API使用说明

本框架有 LXSegmentTitleView 和 LXScrollContentView 两个类,它们完全独立,可以根据项目需求选择使用。

LXSegmentTitleView表示上方标题区域,它的具体使用方法如下:

/** 文字未选中颜色,默认black */@property (nonatomic, strong) UIColor *normalColor;/** 文字选中和下方滚动条颜色,默认red */@property (nonatomic, strong) UIColor *selectedColor;/** 第几个标题处于选中状态,默认为0 */@property (nonatomic, assign) NSInteger selectedIndex;/** 每个标题宽度,默认85.f */@property (nonatomic, assign) CGFloat titleWidth;/** 标题字体font,默认14.f */@property (nonatomic, strong) UIFont *titleFont;/** 下方滚动指示条高度,默认2.f */@property (nonatomic, assign) CGFloat indicatorHeight;/** 选中标题回调block */@property (nonatomic, copy) BMPageTitleViewSelectedBlock selectedBlock;/** 刷新界面 @param titles 标题数组 */- (void)reloadViewWithTitles:(NSArray *)titles;

LXScrollContentView 表示下方滚动内容区域,它的具体使用方法如下:

/** 设置当前滚动到第几个页面,默认为0 */@property (nonatomic, assign) NSInteger currentIndex;/** 页面滚动停止时触发block回调 */@property (nonatomic, copy) LXScrollContentViewBlock scrollBlock;/** 刷新页面内容 @param childVcs 当前View需要装入的控制器集合 @param parentVC 当前View所在的父控制器 */- (void)reloadViewWithChildVcs:(NSArray *)childVcs parentVC:(UIViewController *)parentVC;

以下是一个在ViewController中具体使用案例

// 初始化UI- (void)setupUI { self.titleView = [[LXSegmentTitleView alloc] initWithFrame:CGRectZero]; self.titleView.itemMinMargin = 15.f; self.titleView.delegate = self; self.titleView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1]; [self.view addSubview:self.titleView]; self.contentView = [[LXScrollContentView alloc] initWithFrame:CGRectZero]; self.contentView.delegate = self; [self.view addSubview:self.contentView];}// 调整titleView和contentView的frame- (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.titleView.frame = CGRectMake(0, 0, self.view.frame.size.width, 35); self.contentView.frame = CGRectMake(0, 35, self.view.frame.size.width, self.view.frame.size.height - 35);}// 刷新titleView和contentView的数据源,根据项目需求自行选择数据源- (void)reloadData { NSArray *titles = @[@"首页", @"体育在线", @"科技日报", @"生活", @"本地", @"精彩视频", @"娱乐", @"时尚", @"房地产", @"经济"]; self.titleView.segmentTitles = titles; NSMutableArray *vcs = [[NSMutableArray alloc] init]; for (NSString *title in titles) { LXTestViewController *vc = [[LXTestViewController alloc] init]; vc.category = title; [vcs addObject:vc]; } [self.contentView reloadViewWithChildVcs:vcs parentVC:self]; self.titleView.selectedIndex = 2; self.contentView.currentIndex = 2;}

4.期望

1.这是 LXScrollContentView 框架发布的第一个版本,还有很多不完善的地方,欢迎大家提出bug。

2.LXScollTitleView 暂时只有一种样式,我会尽快增加更多样式。

3.LXScrollContentView目前使用UICollectionView滑动,在性能方面已经比较优秀。接下来考虑加入cache功能,争取达到更加顺滑的效果。

4.大家如果觉得本框架不错,希望你们可以 Star 一下,我会更有动力的去不断完善。

5.我的邮箱账号:liuxinghenau@163.com ,简书地址:http://jianshu.com/u/f367c6621844 ,大家有问题可以随时联系。

5.使用问题

最近好多同学使用此框架发现设置正确的frame,但控件在屏幕位置显示并不正确。这是因为iOS系统导航栏透明对滚动视图的影响,可以在 viewDidLoad 里面设置写上 self.automaticallyAdjustsScrollViewInsets = NO 解决此问题

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:hawk - 一个快速和易用的键值对数据存储框架,支持AES加密
下一篇:计算机网络基础之传输层的功能和服务
相关文章

 发表评论

暂时没有评论,来抢沙发吧~