// // PBComponentHierarchyView.m // IphoneBIMe // // Created by zjf on 2020/11/9. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBComponentHierarchyView.h" static NSString *const cellID = @"CellID"; @interface PBComponentHierarchyView() @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UITableView *tableView; @end @implementation PBComponentHierarchyView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; [self addSubview:self.bgView]; [self setupUI]; } return self; } - (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.3 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; self.bgView.y = PBScreenHeight; }completion:^(BOOL finished) { for (UIView *cover in PBKeyWindow.subviews) { if ([cover isKindOfClass:[PBComponentHierarchyView class]]) { [cover removeFromSuperview]; } } }]; } - (void)show { [UIView animateWithDuration:0.3 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5]; self.bgView.y = PBScreenHeight - self.visualViewHeight; }]; } #pragma mark - 懒加载 - (UIView *)bgView { if (_bgView == nil) { _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)]; _bgView.backgroundColor = [UIColor whiteColor]; } return _bgView; } - (void)setVisualViewHeight:(NSInteger)visualViewHeight { _visualViewHeight = visualViewHeight; } - (void)setupUI { self.tableView = [[UITableView alloc] init]; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID]; [self.bgView addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgView).offset(14); make.left.right.bottom.equalTo(self.bgView); make.height.equalTo(@200); }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; NSDictionary *dict = self.dataArr[indexPath.row]; cell.textLabel.text = [dict valueForKey:@"bmc_name"]; return cell; } - (void)setDataArr:(NSArray *)dataArr { _dataArr = dataArr; [self.tableView reloadData]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end