美文网首页
选项卡视图

选项卡视图

作者: CDLOG | 来源:发表于2019-05-09 11:09 被阅读0次

主流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 {}

相关文章

网友评论

      本文标题:选项卡视图

      本文链接:https://www.haomeiwen.com/subject/ixapiqtx.html