// // KBMyFansViewController.m // YouHuiProject // // Created by 小花 on 2018/5/19. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBMyFansViewController.h" #import "KBOrderTableView.h" #import "MLMSegmentHead.h" #import "MLMSegmentManager.h" #import "KBChildFansViewController.h" #import "KBFansHeaderView.h" #import "KBShowFansHelpView.h" #import "CCAlertShowView.h" #import "KBPotentialFansViewController.h" @interface KBMyFansViewController () < UITableViewDelegate, UITableViewDataSource, MLMSegmentScrollDelegate > @property (nonatomic, strong) KBOrderTableView *tableView; @property (nonatomic, strong) KBFansHeaderView *headerView; @property (nonatomic, strong) MLMSegmentHead *titleView; @property (nonatomic, strong) MLMSegmentScroll *segScroll; @property (nonatomic, strong) NSMutableArray *vcList; @property (nonatomic, assign) BOOL canScroll; @property (nonatomic, strong) UIButton *rightHelpBtn; @end @implementation KBMyFansViewController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configTableView]; [self creatHeaderViewAndFooterView]; } - (void)configTableView { // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"leaveTop" object:nil]; // self.canScroll = YES; // self.headerView = [[KBFansHeaderView 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]]; self.rightHelpBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [self.rightHelpBtn setImage:[UIImage imageNamed:@"helpmonth"] forState:UIControlStateNormal]; [self.rightHelpBtn addTarget:self action:@selector(showHelpAlert) forControlEvents:UIControlEventTouchUpInside]; self.rightHelpBtn.hidden = YES; [self.navigationBar setCustomRightButtons:@[self.rightHelpBtn]]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)creatHeaderViewAndFooterView { self.view.backgroundColor = [UIColor whiteColor]; NSArray *titleArr = @[@"全部好友",@"直属好友",@"推荐好友",@"潜在好友"]; for (int i = 0; i < titleArr.count; i++) { if (i == 3) { KBPotentialFansViewController *child = [[KBPotentialFansViewController alloc] init]; [self.vcList addObject:child]; }else { KBChildFansViewController *child = [[KBChildFansViewController alloc] init]; child.type=i; [self.vcList addObject:child]; } } self.segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ChildTableViewHeight) vcOrViews:self.vcList]; self.segScroll.bounces = NO; __weak typeof(self) weskSelf = self; self.segScroll.showingIndex = ^(NSInteger index) { weskSelf.rightHelpBtn.hidden = index!=3; }; 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 === - (void)showHelpAlert { KBShowFansHelpView *popView = [[KBShowFansHelpView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-80, 213)]; CCAlertShowView *showView = [CCAlertShowView alertViewWithView:popView]; popView.dismissAction = ^{ [showView dismiss]; }; [showView show]; } #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 (KBChildFansViewController *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.estimatedRowHeight = 0; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; _tableView.backgroundColor = [UIColor yhGrayColor]; _tableView.bounces = NO; _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