CNLiveCMineInteTaskViewController.m 7.66 KB
//
//  CNLiveCMineInteTaskViewController.m
//  CNLiveCMineModule
//
//  Created by open on 2021/12/30.
//

#import "CNLiveCMineInteTaskViewController.h"
#import "CNLiveCMineInteTaskListViewController.h"
static NSInteger const kCNLiveSectionTitleHeight = 44;//标题显示
static NSInteger const kCNLiveSectionHeaderHeight = 140;//头视图高度

@interface CNLiveCMineInteTaskViewController ()<JXCategoryViewDelegate,JXPagerViewDelegate>
@property (nonatomic, strong) NSMutableArray<CNLiveCMineInteTaskListViewController *> *viewControllers;
@property (nonatomic, strong) CNLiveCMineInteTaskListModel * taskModel;//数据源
@property (nonatomic, strong) CNLiveNavigationBar * navigationBar;//导航栏
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXPagerView *pagingView;
@property (nonatomic, strong) UIImageView * backView;

@property (nonatomic, assign) CGFloat header_height;//高度

@end

@implementation CNLiveCMineInteTaskViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (instancetype)initWithTaskModel:(CNLiveCMineInteTaskListModel *)taskModel
{
    self = [super init];
    if (self) {
        _taskModel = taskModel;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.header_height = kCNLiveSectionHeaderHeight + (kCNLiveSectionTitleHeight/2);
    self.view.backgroundColor = UIColorHex(0xf9f9f9);
    
    [self.view addSubview:self.backView];
    [self.view addSubview:self.pagingView];
    [self.view addSubview:self.navigationBar];
}
#pragma mark - JXPagingViewDelegate

- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kCNLiveSectionHeaderHeight)];
    headerView.backgroundColor = [UIColor clearColor];
    return headerView;
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    return kCNLiveSectionHeaderHeight;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return kCNLiveSectionTitleHeight;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return self.categoryView;
}

- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
    return 2;
}

- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
    return self.viewControllers[index];
}

- (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {

    CGFloat offsetY = scrollView.contentOffset.y;
    self.backView.height = offsetY < 0 ? self.header_height + fabs(offsetY) : self.header_height;
    self.backView.width = offsetY < 0 ? SCREEN_WIDTH + fabs(offsetY) : SCREEN_WIDTH;
    self.backView.left = self.backView.width > SCREEN_WIDTH ? -(self.backView.width - SCREEN_WIDTH)/2 : 0;
}

-(UIStatusBarStyle)preferredStatusBarStyle
{
    if (@available(iOS 13.0, *)) {
        return UIStatusBarStyleDarkContent;
    } else {
        return UIStatusBarStyleDefault;
    }
}
#pragma mark =
-(NSMutableArray<CNLiveCMineInteTaskListViewController *> *)viewControllers
{
    if (!_viewControllers) {
        _viewControllers = [[NSMutableArray alloc] initWithArray:@[
            [[CNLiveCMineInteTaskListViewController alloc] initWithTaskArray:self.taskModel.dailyTask TaskVC:self],
            [[CNLiveCMineInteTaskListViewController alloc] initWithTaskArray:self.taskModel.firstTask TaskVC:self]
        ]];
    }
    return _viewControllers;
}

#pragma mark = getter
-(JXPagerView *)pagingView
{
    if (_pagingView == nil) {
        _pagingView = [[JXPagerView alloc] initWithDelegate:self listContainerType:JXPagerListContainerType_CollectionView];
        _pagingView.frame = CGRectMake(0, kNavigationBarHeight, KScreenWidth, KScreenHeight);
        _pagingView.backgroundColor = kClearColor;
        _pagingView.mainTableView.backgroundColor = kClearColor;
        _pagingView.pinSectionHeaderVerticalOffset = kCNLiveSectionHeaderHeight;
        _pagingView.automaticallyDisplayListVerticalScrollIndicator = NO;
        _pagingView.listContainerView.categoryNestPagingEnabled = YES;
        self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
    }
    return _pagingView;
}
- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kCNLiveSectionTitleHeight)];
        _categoryView.titles = @[@"每日任务",@"首次任务"];
        _categoryView.titleFont = [UIFont systemFontOfSize:15.0f];
        _categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f];
        _categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:16.0f];
        _categoryView.titleColor = UIColorHex(#999999);
        _categoryView.titleSelectedColor = UIColorHex(#333333);
        _categoryView.collectionView.backgroundColor = [UIColor clearColor];
        _categoryView.backgroundColor = [UIColor clearColor];
        _categoryView.separatorLineShowEnabled = YES;
        _categoryView.delegate = self;
        
        JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
        lineView.indicatorColor = UIColorHex(#0AC94A);
        lineView.verticalMargin = 5;
        lineView.indicatorWidth = 10;
        _categoryView.indicators = @[lineView];
        
        UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 30, kCNLiveSectionTitleHeight)];
        radiusView.backgroundColor = [UIColor whiteColor];
        radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
        radiusView.layer.shadowOffset = CGSizeMake(0, 0);
        radiusView.layer.shadowOpacity = 0.3;
        radiusView.layer.shadowRadius = 8;
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 30, kCNLiveSectionTitleHeight) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.path = maskPath.CGPath;
        radiusView.layer.mask = maskLayer;
        [_categoryView insertSubview:radiusView belowSubview:_categoryView.collectionView];
        
    }
    return _categoryView;
}

- (CNLiveNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [CNLiveNavigationBar navigationBar];
        _navigationBar.leftImage = [CNLiveCMineService imageWithMineName:@"c_mine_skip_push_back"];
        __weak typeof(self) weakSelf = self;
        _navigationBar.lineHidden = YES;
        _navigationBar.backgroundColor = [UIColor whiteColor];
        _navigationBar.onClickLeftButton = ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
        _navigationBar.title.text = @"做任务 赚积分";
        _navigationBar.title.textColor = UIColorHex(#3A3A3A);
        _navigationBar.right.hidden = YES;
    }
    return _navigationBar;
}
-(UIImageView *)backView
{
    if (!_backView) {
        _backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, kScreenWidth, kCNLiveSectionHeaderHeight + (kCNLiveSectionTitleHeight/2))];
        _backView.contentMode = UIViewContentModeScaleToFill;
        _backView.clipsToBounds = YES;
        _backView.backgroundColor = UIColorHex(0xf9f9f9);
        _backView.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_task_groud"];
    }
    return _backView;
}

@end