iOS:多效果的CategoryView
There is an English version of README here. just click it!
A powerful and easy to use category view (segmentedcontrol, segmentview, pagingview, pagerview, pagecontrol) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
与其他的同类三方库对比的优点:
- 使用POP(Protocol Oriented Programming面对协议编程)封装指示器逻辑,可以为所欲为的自定义指示器效果;
- 提供更加全面丰富的效果,交互更加顺畅;
- 使用子类化管理cell样式,逻辑更清晰,扩展更简单;
效果预览
要求
- iOS 8.0+
- Xcode 9+
- Objective-C
安装
手动
Clone代码,把Sources文件夹拖入项目,#import “JXCategoryView.h”,就可以使用了;
CocoaPods
target '<Your Target Name>' dopod 'JXCategoryView'
end
结构图
- 指示器样式自定义:使用POP(Protocol Oriented Programming面对协议编程)封装指示器逻辑,只要遵从
JXCategoryIndicatorProtocol
协议,就可以实现你的指示器效果。参考:JXCategoryIndicatorLineView; - Cell样式自定义:使用子类化,基类搭建基础,子类实现特殊效果。便于代码管理,功能扩展;参考:JXCategoryNumberView;
特殊说明
- 自定义:即使提供了灵活扩展,我的源码也不可能满足所有情况,建议大家可以通过fork仓库,维护自己的一套效果。也可以直接拖入源文件进行修改。
- 个人主页效果:上下左右滚动且HeaderView悬浮的实现,用的是我写的这个库JXPagingView。
- 垂直列表滚动:参考demo工程的
VerticalListViewController
,未做功能封装,参考里面的代码做,多注意注释,就可以实现了。
常用属性说明
JXCategoryView常用属性说明
属性 | 说明 |
---|---|
defaultSelectedIndex | 默认选中的index,用于初始化时指定选中某个index |
selectedIndex | 只读属性,当前选中的index |
cellWidth | cell的宽度,默认:JXCategoryViewAutomaticDimension |
cellSpacing | cell之间的间距,默认20 |
cellWidthIncrement | cell宽度的补偿值,默认0 |
averageCellWidthEnabled | 当cell内容总宽度小于JXCategoryBaseView的宽度,是否将cellWidth均分。默认为YES。 |
contentScrollView |
需要关联的contentScrollView,内部监听contentOffset
|
Cell样式常用属性说明
属性 | 说明 |
---|---|
titleColor | titleLabel未选中颜色 默认:[UIColor blackColor] |
titleSelectedColor | titleLabel选中颜色 默认:[UIColor redColor] |
titleFont | titleLabel的字体 默认:[UIFont systemFontOfSize:15] |
titleColorGradientEnabled | title的颜色是否渐变过渡 默认:NO |
titleLabelMaskEnabled | titleLabel是否遮罩过滤 默认:NO |
titleLabelZoomEnabled | titleLabel是否缩放 默认:NO |
titleLabelZoomScale | citleLabel缩放比例 默认:1.2 |
imageZoomEnabled | imageView是否缩放 默认:NO |
imageZoomScale | imageView缩放比例 默认:1.2 |
separatorLineShowEnabled | cell分割线是否展示 默认:NO (颜色、宽高可以设置) |
JXCategoryTitleImageType | 图片所在位置:上面、左边、下面、右边 默认:左边 |
指示器常用属性说明
属性 | 说明 |
---|---|
JXCategoryIndicatorComponentView.componentPosition | 指示器的位置 默认:Bottom |
JXCategoryIndicatorComponentView.scrollEnabled | 手势滚动、点击切换的时候,是否允许滚动,默认YES |
JXCategoryIndicatorLineView.lineStyle | 普通、京东、爱奇艺效果 默认:Normal |
JXCategoryIndicatorLineView.lineScrollOffsetX | 爱奇艺效果专用,line滚动时x的偏移量,默认为10; |
JXCategoryIndicatorLineView.indicatorLineWidth | 默认JXCategoryViewAutomaticDimension(与cellWidth相等) |
JXCategoryIndicatorLineView.indicatorLineViewHeight | 默认:3 |
JXCategoryIndicatorLineView.indicatorLineViewCornerRadius | 默认JXCategoryViewAutomaticDimension (等于self.indicatorLineViewHeight/2) |
JXCategoryIndicatorLineView.indicatorLineViewColor | 默认为[UIColor redColor] |
JXCategoryIndicatorTriangleView.triangleViewSize | 默认:CGSizeMake(14, 10) |
JXCategoryIndicatorTriangleView.triangleViewColor | 默认为[UIColor redColor] |
JXCategoryIndicatorImageView.indicatorImageView | 设置image |
JXCategoryIndicatorImageView.indicatorImageViewRollEnabled | 是否允许滚动,默认:NO |
JXCategoryIndicatorImageView.indicatorImageViewSize | 默认:CGSizeMake(30, 20) |
JXCategoryIndicatorBackgroundView.backgroundViewWidth | 默认JXCategoryViewAutomaticDimension(与cellWidth相等) |
JXCategoryIndicatorBackgroundView.backgroundViewWidthIncrement | 宽度增量补偿,因为backgroundEllipseLayer一般会比实际内容大一些。默认10 |
JXCategoryIndicatorBackgroundView.backgroundViewHeight | 默认JXCategoryViewAutomaticDimension(与cell高度相等) |
JXCategoryIndicatorBackgroundView.backgroundViewCornerRadius | 默认JXCategoryViewAutomaticDimension(即backgroundViewHeight/2) |
JXCategoryIndicatorBackgroundView.backgroundViewColor | 默认为[UIColor redColor] |
JXCategoryIndicatorBallView.ballViewSize | 默认:CGSizeMake(15, 15) |
JXCategoryIndicatorBallView.ballScrollOffsetX | 小红点的偏移量 默认:20 |
JXCategoryIndicatorBallView.ballViewColor | 默认为[UIColor redColor] |
可以多个IndicatorView搭配使用,但是效果需要自己把控,效果不是越多越好。参考混合使用;
使用
self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, WindowsSize.width, categoryViewHeight)];
self.categoryView.delegate = self;
self.categoryView.contentScrollView = self.scrollView;
//------指示器属性配置------//
//lineView
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
//triangleView
JXCategoryIndicatorTriangleView *triangleView = [[JXCategoryIndicatorTriangleView alloc] init];
lineView.indicatorLineWidth = 20;
//ballView
JXCategoryIndicatorBallView *ballView = [[JXCategoryIndicatorBallView alloc] init];
//backgroundView
JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];titleCategoryView.indicators = @[lineView, triangleView, ballView, backgroundView];[self.view addSubview:self.categoryView];
- 单个cell刷新:比如红点示例里面,调用
- (void)reloadCell:(NSUInteger)index
- 所有状态重置:数据源、属性配置有变动时(比如从服务器拉取回来数据),需要调用
reloadDatas
方法刷新状态。
指示器样式自定义
仓库自带:JXCategoryIndicatorLineView、JXCategoryIndicatorTriangleView、JXCategoryIndicatorImageView、JXCategoryIndicatorBackgroundView、JXCategoryIndicatorBallView
主要实现的方法:
- 继承JXCategoryIndicatorComponentView,内部遵从了JXCategoryIndicatorProtocol
协议;
- 实现协议方法,自定义效果:
- - (void)jx_refreshState:(CGRect)selectedCellFrame
初始化或reloadDatas,重置状态;
- - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent
contentScrollView在进行手势滑动时,处理指示器跟随手势变化UI逻辑;
- - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition
根据选中的某个cell,处理过渡效果;
具体实例:参考demo工程里面的JXCategoryIndicatorDotLineView
Cell子类化注意事项
仓库自带:JXCategoryTitleView、JXCategoryTitleImageView、JXCategoryNumberView、JXCategoryDotView、JXCategoryImageView
主要实现的方法:
- - (Class)preferredCellClass
返回自定义的cell;
- - (void)refreshDataSource
刷新数据源,使用自定义的cellModel;
- - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index
初始化、reloadDatas时对数据源重置;
- - (CGFloat)preferredCellWidthWithIndex:(NSInteger)index
根据cell的内容返回对应的宽度;
- - (void)refreshSelectedCellModel:(JXCategoryBaseCellModel *)selectedCellModel unselectedCellModel:(JXCategoryBaseCellModel *)unselectedCellModel
cell选中时进行状态刷新;
- - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio
cell左右滚动切换的时候,进行状态刷新;
具体实例:参考demo工程里面的JXCategoryTitleAttributeView
继承提示
- 任何子类化,view、cell、cellModel三个都要子类化,即使某个子类cell什么事情都不做。用于维护继承链,以免以后子类化都不知道要继承谁了;
- 如果你先完全自定义cell里面的内容,那就继承
JXCategoryIndicatorView、JXCategoryIndicatorCell、JXCategoryIndicatorCellModel
,就像JXCategoryTitleView、JXCategoryTitleCell、JXCategoryTitleCellModel
那样去做; - 如果你只是在父类进行一些微调,那就继承目标view、cell、cellModel,对cell原有控件微调、或者加入新的控件皆可。就像
JXCategoryTitleImageView系列、JXCategoryTitleAttributeView系列
那样去做;
侧滑手势
首先,在viewDidAppear加上下面代码:
- (void)viewDidAppear:(BOOL)animated {[super viewDidAppear:animated];self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
}
系统默认返回Item
- 点击处理:
#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
自定义导航栏返回Item
- 设置代理:self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
- 实现代理方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {return YES;
}
- 点击处理:
#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
contentScrollView
- 布局灵活:JXCategoryView没有与contentScrollView强关联,你甚至可以不设置这个属性,把它当做简单的SegmentedControl。他们之间布局没有任何要求,可以把JXCategoryView放入导航栏、UITableViewSectionHeader等任何你想要的地方。
- 点击处理:因为充分解耦,在JXCategoryView点击回调中,你需要添加如下代码进行内容滚动切换:
#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {[self.scrollView setContentOffset:CGPointMake(self.scrollView.bounds.size.width*index, 0) animated:YES];
}
更新记录
- 2018.8.21 发布1.0.0版本,更新内容:使用POP(面向协议编程)重构指示器视图;迁移指南
- 2018.8.22 发布1.0.1版本,更新内容:删除zoomEnabled,新增titleLabelZoomEnabled、imageZoomEnabled;
- 2018.8.23 发布1.0.2版本,更新内容:添加cellWidthZoomEnabled实现腾讯视频效果;
- 2018.8.24 发布1.0.3版本,更新内容:添加垂直列表滚动效果、指示器添加verticalMargin属性、JXCategoryViewDelegate代理方法优化;
iOS:多效果的CategoryView相关推荐
- [纪录]仿IOS滚轮效果(竖直滑动选择器)
今天想做一个类似这样的一个效果,可是UI的模板是参考IOS做的,于是就各种百度各种搜,最后让我找到了一个仿IOS滚轮的一个Demo,稍微研究了一下,发上来,大家一起学习,以后也方便我查看,就不用再去百 ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- vue中禁止ios橡皮筋效果(亲测有效)
相信有很多前端的朋友都遇到过这个问题,这个问题真的很头疼.ios的橡皮筋效果会带来一些莫名其妙的bug.如果直接对body禁止的话,那整个页面都无法滑动了.所以我今天带来一个解决方案.原博客找不到了, ...
- android 按钮回弹效果,Android仿IOS回弹效果 支持任何控件
本文实例为大家分享了Android仿IOS回弹效果的具体代码,供大家参考,具体内容如下 效果图: 导入依赖: dependencies { // ... compile 'me.everything: ...
- android 布局回弹,Android仿IOS回弹效果 支持任何控件
本文实例为大家分享了Android仿IOS回弹效果的具体代码,供大家参考,具体内容如下 效果图: 导入依赖: dependencies { // ... compile 'me.everything: ...
- android 仿ios毛玻璃,类 iOS 毛玻璃效果控件 BlurView
软件介绍 BlurView 是Android下类似 iOS 毛玻璃效果控件. 使用: android:id="@+id/blurView" android:layout_width ...
- 解决IOS橡皮筋效果
1.一棍子打死 (全部滚动条失效) app.vue文件mounted中 document.body.addEventListener('touchmove', function (e) {e.prev ...
- ios 扑克牌效果轮播_iOS一行代码实现立体轮播图
示例图片 bannergif.gif 使用方法 1. 初始化 (instancetype)initWithFrame:(CGRect)frame WithBannerSource:(NinaBanne ...
- iOS 毛玻璃效果的实现方法
iOS开发中有的时候需要将图片设置模糊,来实现特定的效果获取更好的用户体验, iOS7之后半透明模糊效果得到大范围使用的比较大,现在也可以看到很多应用局部用到了图片模糊效果,可以通过高斯模糊和毛玻璃效 ...
最新文章
- 微信小程序 在使用wx.request时显示加载中
- 检测到USB设备插入写法1
- 关于python的单线程和多线程
- 第一人称视角获得运动方向和视角的夹角
- HDU - 5919 Sequence II
- vb 根据pid获取句柄_C++中避免返回指向对象内部的句柄(handles)
- sql运算符_SQL AND运算符解释语法示例
- maven aliyun 仓库速度就是快
- linux中切换到上级目录,vsftp中控制用户是否允许切换到上级目录
- dio设置自定义post请求_基于dio库封装flutter项目的标准网络框架
- 银行招聘考试题库计算机,2019银行招聘计算机试题(一)答案
- 阿里完成首个可控量子比特研发;45 名谷歌员工举报不公对待;Swoft 2.0.6 正式版发布 | 极客头条...
- 贝叶斯分析——从数值积分到MCMC
- AtCoder Regular Contest 076E Coneected?
- WPF与输入法冲突研究之三:韩文输入法在不同平台,WinForm/WPF下的区别
- 因为此网站使用了 hsts_HSTS原理及实践
- 修改Apache配置文件开启gzip压缩传输
- android自定义pickerview,开源项目 好用的PickerView库了
- matlab模糊数学隶属问题,模糊数学模型matlab
- 安卓手机权限总结安卓权限列表
热门文章
- 953. 验证外星语词典( 简单模拟 + 自定义定制排序 )
- php获取证书编号没有serialNumberHex只有serialNumber处理方法
- uni-app转小程序遇到的问题 (组件使用插槽的问题)(跨端兼容、条件编译)(小程序自定义胶囊按钮封装)(uni-app挂载原型链)
- 在Origin绘图和表格中插入Latex公式
- wince博客名人堂
- Dcloud mui初级入门资源
- C语言及ARM中堆栈指针SP设置的理解与总结
- Ps 如何制作网格背景
- 不能编程、烧钱、没用?潘建伟直播回应“九章”量子计算争议
- Response对象-响应字符数据