admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
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
132
133
134
135
136
137
138
139
140
141
142
143
//
//  PPTVPppView.m
//  BuWanVideo2.0
//
//  Created by Aeline on 2021/5/15.
//  Copyright © 2021 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "PPTVPppView.h"
#import "PPTVPopCell.h"
 
@interface PPTVPppView () <UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate>
@property (nonatomic, nullable, strong) UIView *viewBG;
@property (nonatomic, nullable, strong) UITableView *tabView;
@property (nonatomic, nullable, strong) UIImageView *imageViewTT;
 
@property(nonatomic, nullable, strong) NSArray *arrayContent;
@end
 
@implementation PPTVPppView
 
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UICOLOR_FROM_RGB(0x000000, 0.5);
        
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismisView)];
        tap.delegate = self;
        [self addGestureRecognizer:tap];
        
        self.arrayContent = @[@{@"name" : @"刷新", @"icon" : @"pptv_refresh"} ,
                              @{@"name" : @"复制链接", @"icon" : @"pptv_copy"} ,
                              @{@"name" : @"用其他浏览器打开", @"icon" : @"pptv_other"}];
        [self setupViewConfig];
    }
    return self;
}
 
- (void)setupViewConfig {
    [self addSubview:self.imageViewTT];
    self.imageViewTT.sd_layout.rightSpaceToView(self, 8).topSpaceToView(self, 1).widthIs(33).heightIs(24);
    
    [self addSubview:self.viewBG];
    self.viewBG.sd_layout.rightSpaceToView(self, 5).topSpaceToView(self, 8).widthIs(180).heightIs(138);
    self.viewBG.sd_cornerRadius = @6;
    
    [self.viewBG addSubview:self.tabView];
}
 
- (void)dismisView {
    self.hidden = YES;
}
 
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    // 输出点击的view的类名,则不截获Touch事件
    NSLog(@"%@", NSStringFromClass([touch.view class]));
    if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
        if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
            return NO;
        }
    }
    return YES;
}
 
#pragma mark UITableViewDelegate, UITableViewDataSource
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self dismisView];
    if (_delegate && [_delegate respondsToSelector:@selector(selectType:)]) {
        [_delegate selectType:self.arrayContent[indexPath.section][@"name"]];
    }
}
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.arrayContent.count;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIden = @"PPTVPopCell";
    PPTVPopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIden];
    if (!cell){
        cell = [[PPTVPopCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIden];
    }
    cell.index = indexPath.section;
    cell.data = self.arrayContent[indexPath.section];
    return cell;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    return view;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    return view;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
 
- (UIView *)viewBG {
    if (!_viewBG) {
        _viewBG = [[UIView alloc] init];
        _viewBG.backgroundColor = [UIColor whiteColor];
    }
    return _viewBG;
}
 
- (UITableView *)tabView {
    if (!_tabView) {
        _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, (172),  137) style:UITableViewStyleGrouped];
        _tabView.delegate = self;
        _tabView.dataSource = self;
        _tabView.estimatedRowHeight = 47;
        _tabView.estimatedSectionFooterHeight = 0;
        _tabView.estimatedSectionHeaderHeight = 0;
        _tabView.backgroundColor = [UIColor whiteColor];
        _tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tabView.showsVerticalScrollIndicator = YES;
        _tabView.scrollEnabled = NO;
    }
    return _tabView;
}
 
- (UIImageView *)imageViewTT {
    if (!_imageViewTT) {
        _imageViewTT = [[UIImageView alloc] init];
        _imageViewTT.image = [UIImage imageNamed:@"pptv_bg"];
    }
    return _imageViewTT;
}
@end