// // ReplayMeVC.m // smartRhino // // Created by niuzhen on 2020/6/11. // Copyright © 2020 tederen. All rights reserved. // #import "ReplayMeVC.h" #import "MyTDGroupView.h" #import "ReplayMeCell.h" #import "ShowBtn.h" #import "YCMenuView.h" #import "ReplayMeLikeVC.h" #import "ReplayMeSearchVC.h" @interface ReplayMeVC () @property (weak, nonatomic) IBOutlet UIView *navBar; @property (weak, nonatomic) IBOutlet UIView *HeadView; @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (strong, nonatomic) ShowBtn *titleBtn; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (strong, nonatomic) NSMutableArray *taskActionArray; @property (assign, nonatomic) BOOL replayMe; @end @implementation ReplayMeVC +(ReplayMeVC *)initReplayMeVC{ ReplayMeVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"ReplayMeVC"]; return controller; } - (ShowBtn *)titleBtn { if (!_titleBtn) { _titleBtn = [ShowBtn new]; } return _titleBtn; } - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } - (void)autoSizeBtn:(NSString *)title { [self.titleBtn setLabelTitle:title]; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.tableView.delegate = self; self.tableView.dataSource = self; [self.HeadView addSubview:self.SearchView]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(6); make.left.right.mas_equalTo(self.HeadView); make.height.mas_offset(36); }]; WS(weakSelf); [self.SearchView.button setAction:^{ ReplayMeSearchVC * vc = [[ReplayMeSearchVC alloc] init]; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [self.navBar addSubview:self.titleBtn]; [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(self.navBar); }]; [self autoSizeBtn:@"我回复的"]; [self.titleBtn setAction:^{ [weakSelf.titleBtn show]; NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray]; YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:105 relyonView:weakSelf.titleBtn]; view.menuColor = UIColorHex(0xFFFFFF); view.separatorColor = UIColorHex(0xEAEAEA); view.textColor = UIColorHex(0x666666); view.textFont = [UIFont systemFontOfSize:16.0]; view.menuCellHeight = 45; view.maxDisplayCount = 10; view.offset = - 6; [view show]; }]; [self.tableView reloadData]; } -(NSMutableArray *)taskActionArray{ if(!_taskActionArray){ _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"回复我的",@"我回复的", nil]; } return _taskActionArray; } -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{ NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init]; for(int i = 0;i < titleArray.count;i ++){ NSString *titleStr = [titleArray objectAtIndex:i]; WS(weakSelf); YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) { [weakSelf.titleBtn dismiss]; [weakSelf autoSizeBtn:titleStr]; if([@"回复我的" isEqualToString:action.title]){ weakSelf.replayMe = YES; }else{ weakSelf.replayMe = NO; } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); }]; [menuDataSourceArray addObject:actionMenu]; } return menuDataSourceArray; } #pragma mark -UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 20; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (self.replayMe) { return 45.f; }else{ return 0.01f; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01f; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView * view = [UIView new]; if (self.replayMe) { UILabel * label = [UILabel new]; label.font = Kfont(16); label.textColor = UIColorHex(0x0a0a0a); label.text = @"收到的赞"; [view addSubview:label]; [label mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_offset(15); make.centerY.mas_equalTo(view); }]; UIImageView * imgv = [UIImageView new]; imgv.image = IMG(@"right_img"); [view addSubview:imgv]; [imgv mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_offset(-15); make.centerY.mas_equalTo(view); }]; UILabel * redL = [UILabel new]; redL.font = Kfont(11); redL.textColor = UIColorHex(0xFFFFFF); redL.backgroundColor = [UIColor redColor]; redL.text = @"3"; redL.textAlignment = NSTextAlignmentCenter; [view addSubview:redL]; [redL mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(imgv.mas_left).offset(-8); make.centerY.mas_equalTo(view); make.size.mas_offset(CGSizeMake(16, 16)); }]; redL.layer.cornerRadius = 8.f; redL.layer.masksToBounds = YES; UIView * lineV = [UIView new]; lineV.backgroundColor = LINEBGCOLOR; [view addSubview:lineV]; [lineV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.mas_equalTo(view); make.height.mas_offset(0.5); }]; WS(weakSelf); UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { ReplayMeLikeVC * vc = [ReplayMeLikeVC initReplayMeLikeVC]; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [view addGestureRecognizer:tap]; } return view; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ReplayMeCell * cell = [ReplayMeCell configCell:tableView indexPath:indexPath]; cell.redV.hidden = YES; [cell setDatasubText]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } @end