-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathEAFliterMenu.m
146 lines (123 loc) · 5.16 KB
/
EAFliterMenu.m
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
144
145
146
//
// EAFliterMenu.m
// Coding_iOS
//
// Created by Ease on 2017/2/15.
// Copyright © 2017年 Coding. All rights reserved.
//
#import "EAFliterMenu.h"
#import "XHRealTimeBlur.h"
#import "pop.h"
@interface EAFliterMenu ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) XHRealTimeBlur *realTimeBlur;
@property (nonatomic, strong) UITableView *tableview;
@end
@implementation EAFliterMenu
- (id)initWithFrame:(CGRect)frame items:(NSArray *)items{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.items = items;
[self setup];
}
return self;
}
// 设置属性
- (void)setup {
self.backgroundColor = [UIColor clearColor];
_realTimeBlur = [[XHRealTimeBlur alloc] initWithFrame:self.bounds];
_realTimeBlur.clipsToBounds = YES;
_realTimeBlur.blurStyle = XHBlurStyleTranslucentWhite;
_realTimeBlur.showDuration = 0.1;
_realTimeBlur.disMissDuration = 0.2;
typeof(self) __weak weakSelf = self;
_realTimeBlur.willShowBlurViewcomplted = ^(void) {
POPBasicAnimation *alphaAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
alphaAnimation.fromValue = @0.0;
alphaAnimation.toValue = @1.0;
alphaAnimation.duration = 0.3f;
[weakSelf.tableview pop_addAnimation:alphaAnimation forKey:@"alphaAnimationS"];
};
_realTimeBlur.willDismissBlurViewCompleted = ^(void) {
POPBasicAnimation *alphaAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
alphaAnimation.fromValue = @1.0;
alphaAnimation.toValue = @0.0;
alphaAnimation.duration = 0.2f;
[weakSelf.tableview pop_addAnimation:alphaAnimation forKey:@"alphaAnimationE"];
};
_realTimeBlur.didDismissBlurViewCompleted = ^(BOOL finished) {
[weakSelf removeFromSuperview];
};
_realTimeBlur.hasTapGestureEnable = YES;
_tableview = ({
UITableView *tableview=[[UITableView alloc] initWithFrame:self.bounds];
tableview.backgroundColor=[UIColor clearColor];
tableview.delegate=self;
tableview.dataSource=self;
[tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
tableview.tableFooterView=[UIView new];
tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
tableview.estimatedRowHeight = 0;
tableview.estimatedSectionHeaderHeight = 0;
tableview.estimatedSectionFooterHeight = 0;
tableview;
});
[self addSubview:_tableview];
_tableview.contentInset=UIEdgeInsetsMake(15, 0,0,0);
int contentHeight=320;
if ((kScreen_Height-64)>contentHeight) {
UIView *contentView=[[UIView alloc] initWithFrame:CGRectMake(0,64+contentHeight , kScreen_Width, kScreen_Height-64-contentHeight)];
contentView.backgroundColor=[UIColor clearColor];
[self addSubview:contentView];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickedContentView:)];
[contentView addGestureRecognizer:tapGestureRecognizer];
}
}
#pragma mark -- event & action
- (void)showMenuInView:(UIView *)containerView{
_isShowing= YES;
[containerView addSubview:self];
[_realTimeBlur showBlurViewAtView:self];
[_tableview reloadData];
}
- (void)dismissMenu{
UIView *presentView=[[[UIApplication sharedApplication].keyWindow rootViewController] view];
if ([[presentView.subviews firstObject] isMemberOfClass:NSClassFromString(@"RDVTabBar")]) {
[presentView bringSubviewToFront:[presentView.subviews firstObject]];
}
_isShowing= NO;
[_realTimeBlur disMiss];
}
#pragma mark table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _items.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
cell.backgroundColor=[UIColor clearColor];
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
UILabel *titleL = [UILabel labelWithFont:[UIFont systemFontOfSize:15] textColor:indexPath.row == _selectIndex? kColorLightBlue: kColor222];
titleL.text = _items[indexPath.row];
[cell.contentView addSubview:titleL];
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(cell);
make.left.equalTo(cell).offset(20);
}];
cell.accessoryType = indexPath.row == _selectIndex? UITableViewCellAccessoryCheckmark: UITableViewCellAccessoryNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self dismissMenu];
_selectIndex = indexPath.row;
if (_clickBlock) {
_clickBlock(_selectIndex);
}
}
- (void)didClickedContentView:(UIGestureRecognizer *)sender {
[self dismissMenu];
}
@end