zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  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()<UITableViewDataSource, UITableViewDelegate>
@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<UITouch *> *)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