// // KBCommissionMainViewController.m // YouHuiProject // // Created by 小花 on 2018/5/18. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBCommissionMainViewController.h" #import "MLMSegmentHead.h" #import "MLMSegmentManager.h" #import "KBOrderTableView.h" #import "KBChildCommissionController.h" #import "KBCommissionHeaderView.h" #import "KBChildCommissionController.h" @interface KBCommissionMainViewController () < UITableViewDelegate, UITableViewDataSource > @property (nonatomic, strong) KBOrderTableView *tableView; @property (nonatomic, strong) KBCommissionHeaderView *headerView; @property (nonatomic, strong) MLMSegmentHead *titleView; @property (nonatomic, strong) MLMSegmentScroll *segScroll; @property (nonatomic, strong) NSMutableArray *vcList; @property (nonatomic, assign) BOOL canScroll; @end @implementation KBCommissionMainViewController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; // [self configTableView]; [self creatHeaderViewAndFooterView]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)configTableView { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"leaveTop" object:nil]; self.canScroll = YES; self.headerView = [[KBCommissionHeaderView alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH , 135)]; self.tableView.tableHeaderView = self.headerView; [self.view addSubview:self.tableView]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"订单明细"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)creatHeaderViewAndFooterView { self.view.backgroundColor = [UIColor whiteColor]; NSArray *titleArr = @[@"全部",@"已付款",@"已结算",@"已失效"]; for (int i = 0; i < titleArr.count; i++) { KBChildCommissionController *child = [[KBChildCommissionController alloc] init]; switch (i) { case 0: { child.type=4; } break; case 1: { child.type=1; } break; case 2: { child.type=2; } break; case 3: { child.type=0; } break; default: break; } [self.vcList addObject:child]; } self.segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, NavBarHeight+40, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) vcOrViews:self.vcList]; self.segScroll.bounces = NO; self.titleView = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, 40) titles:titleArr headStyle:SegmentHeadStyleDefault layoutStyle:MLMSegmentLayoutDefault]; self.titleView.headColor = [UIColor whiteColor]; self.titleView.bottomLineHeight = 1; self.titleView.bottomLineColor = [UIColor yhGrayColor]; self.titleView.fontScale = 1; self.titleView.fontSize = 14; self.titleView.equalSize = YES; self.titleView.showIndex = 0; self.titleView.selectColor = [UIColor YHColorWithHex:0xff442a]; self.titleView.deSelectColor = [UIColor YHColorWithHex:0x666666]; [MLMSegmentManager associateHead:self.titleView withScroll:self.segScroll completion:^{ [self.view addSubview:self.titleView]; [self.view addSubview:self.segScroll]; }]; } #pragma mark ----- nofi ----- - (void)changeScrollStatus { self.canScroll = YES; for (KBChildCommissionController *childVc in self.vcList) { childVc.childCanScroll = NO; } } #pragma mark --------------------- UITableView delegate ------- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return SCREEN_HEIGHT-NavBarHeight-40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"]; return cell; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return self.titleView; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return self.segScroll; } #pragma mark ----- scroll delegete ---- // //- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // CGFloat bottomCellOffset = [_tableView rectForSection:0].origin.y; // if (scrollView.contentOffset.y >= bottomCellOffset) { // scrollView.contentOffset = CGPointMake(0, bottomCellOffset); // if (self.canScroll) { // self.canScroll = NO; // [self setChildViewControllerCanScroll:YES]; // } // }else{ // if (!self.canScroll) {//子视图没到顶部 // scrollView.contentOffset = CGPointMake(0, bottomCellOffset); // } // } //} - (void)setChildViewControllerCanScroll:(BOOL)childCanScroll { for (KBChildCommissionController *childVc in self.vcList) { childVc.childCanScroll = childCanScroll; if (!childCanScroll) { childVc.tableView.contentOffset = CGPointZero; } } } #pragma mark ---------------- - (KBOrderTableView *)tableView { if (!_tableView) { _tableView = [[KBOrderTableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) style:UITableViewStylePlain]; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.sectionFooterHeight = 0; _tableView.sectionHeaderHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = YES; _tableView.showsVerticalScrollIndicator = NO; [_tableView setSeparatorColor:[UIColor YHColorWithHex:0xdddddd]]; } return _tableView; } - (NSMutableArray *)vcList { if (!_vcList) { _vcList = [NSMutableArray array]; } return _vcList; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end