主流APP分类切换滚动视图
#import "JXCategoryView.h"
#import "CLBaseListController.h"
@interface CLCommunityViewController ()<UITableViewDelegate,UITableViewDataSource,JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
@property (strong,nonatomic) UITableView * tableView;
@property (strong,nonatomic) JXCategoryTitleView * categoryView;
@property (strong,nonatomic) JXCategoryListContainerView * listContainerView;
@property (strong,nonatomic) NSArray<NSString *> * titles;
@end
@implementation CLCommunityViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:@"哈哈"];
[self setUI];
// 初始化JXCategoryTitleView
self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 50)];
self.categoryView.delegate = self;
self.navigationItem.titleView = self.categoryView;
self.titles = @[@"螃蟹", @"麻辣小龙虾", @"苹果"];
self.categoryView.titles = @[@"螃蟹", @"麻辣小龙虾", @"苹果"];
self.categoryView.titleColorGradientEnabled = YES;
[self.view setBackgroundColor:[UIColor redColor]];
// 添加指示器
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorLineViewColor = [UIColor redColor];
lineView.lineStyle = JXCategoryIndicatorLineStyle_Lengthen;
lineView.indicatorLineWidth = JXCategoryViewAutomaticDimension;
self.categoryView.indicators = @[lineView];
// 设置选项卡控制器
self.listContainerView = [[JXCategoryListContainerView alloc] initWithDelegate:self];
// 选项卡控制器的位置大小
self.listContainerView.frame = CGRectMake(0, 0, self.view.width,self.view.height);
[self.view addSubview:self.listContainerView];
//关联cotentScrollView,关联之后才可以互相联动!!!
self.categoryView.contentScrollView = self.listContainerView.scrollView;
// Do any additional setup after loading the view.
}
#pragma mark JXCategoryListContainerViewDelegate 选项卡控制器代理
//返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
//返回遵从`JXCategoryListContentViewDelegate`协议的实例
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
return [[CLBaseListController alloc] init];
}
#pragma mark JXCategoryViewDelegate 选项卡切换代理
//点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
[self.listContainerView didClickSelectedItemAtIndex:index];
}
//点击时
- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
[self.listContainerView didClickSelectedItemAtIndex:index];
}
//滑动时,必须调用!!!
- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
[self.listContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
}
响应控制器
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
- (void)listDidAppear {}
- (void)listDidDisappear {}
网友评论