// // PBMoreFunctionView.m // IphoneBIMe // // Created by zjf on 2018/7/27. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBMoreFunctionView.h" static NSString *const CellID = @"CellID"; @interface PBMoreFunctionView() @property (strong, nonatomic) UIView *bgView; @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UILabel *titleL; @end @implementation PBMoreFunctionView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; [self addSubview:self.bgView]; [self.bgView addSubview:self.titleL]; } return self; } #pragma mark - 懒加载 - (UIView *)bgView { if (_bgView == nil) { _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)]; _bgView.backgroundColor = [UIColor whiteColor]; } return _bgView; } - (UITableView *)tableView { if (_tableView == nil) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, PBScreenWidth, _visualViewHeight - 60) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.rowHeight = 60.f; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.bounces = NO; [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellID]; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } } return _tableView; } - (UILabel *)titleL { if (_titleL == nil) { _titleL = [UILabel z_labelWithText:self.title Color:DescColor isBold:NO Font:DescFontSize]; _titleL.frame = CGRectMake(35, 0, PBScreenWidth - (35 *2), 60); } return _titleL; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint point=[[touches anyObject]locationInView:self]; CALayer *layer=[self.layer hitTest:point]; if (layer ==self.layer) { [self hidden]; } } - (void)hidden { [UIView animateWithDuration:0.5 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; self.bgView.y = PBScreenHeight; }completion:^(BOOL finished) { for (UIView *cover in PBKeyWindow.subviews) { if ([cover isKindOfClass:[PBMoreFunctionView class]]) { [cover removeFromSuperview]; } } }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath]; cell.textLabel.text = self.dataArr[indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:TitleFontSize]; cell.textLabel.textColor = TitleColor; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self hidden]; if (self.seletedIndexBlock) { self.seletedIndexBlock(indexPath.row); } } - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { return 2; } - (void)show { [UIView animateWithDuration:0.5 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5]; self.bgView.y = PBScreenHeight - _visualViewHeight; }]; } - (void)setTitle:(NSString *)title { _title = title; _titleL.text = title; } - (void)setDataArr:(NSArray *)dataArr { _dataArr = dataArr; [self.tableView reloadData]; } - (void)setVisualViewHeight:(NSInteger)visualViewHeight { _visualViewHeight = visualViewHeight; [self.bgView addSubview:self.tableView]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end