forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopFliterMenu.m
More file actions
288 lines (258 loc) · 9.94 KB
/
PopFliterMenu.m
File metadata and controls
288 lines (258 loc) · 9.94 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//
// PopFliterMenu.m
// Coding_iOS
//
// Created by jwill on 15/11/10.
// Copyright © 2015年 Coding. All rights reserved.
//
#define kfirstRowNum 3
#import "PopFliterMenu.h"
#import "XHRealTimeBlur.h"
#import "Coding_NetAPIManager.h"
#import "ProjectCount.h"
#import "Projects.h"
#import "pop.h"
@interface PopFliterMenu()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *items;
@property (nonatomic, strong) XHRealTimeBlur *realTimeBlur;
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) ProjectCount *pCount;
@end
@implementation PopFliterMenu
- (id)initWithFrame:(CGRect)frame items:(NSArray *)items {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.items = @[@{@"all":@""},@{@"created":@""},@{@"joined":@""},@{@"watched":@""},@{@"stared":@""}].mutableCopy;
self.pCount=[ProjectCount new];
self.showStatus=FALSE;
[self setup];
}
return self;
}
- (void)refreshMenuDate
{
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_ProjectsCatergoryAndCounts_WithObj:_pCount andBlock:^(ProjectCount *data, NSError *error) {
if (data) {
[weakSelf.pCount configWithProjects:data];
[weakSelf updateDateSource:weakSelf.pCount];
[weakSelf.tableview reloadData];
}
if(error)
{
NSLog(@"get count error");
}
}];
}
// 设置属性
- (void)setup {
self.backgroundColor = [UIColor clearColor];
_realTimeBlur = [[XHRealTimeBlur alloc] initWithFrame:self.bounds];
_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;
});
[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)showMenuAtView:(UIView *)containerView {
_showStatus=TRUE;
[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]];
}
_showStatus=FALSE;
[_realTimeBlur disMiss];
// [self removeFromSuperview];
}
//组装cell标题
- (NSString*)formatTitleStr:(NSDictionary*)aDic
{
NSString *keyStr=[[aDic allKeys] firstObject];
NSMutableString *convertStr=[NSMutableString new];
if ([keyStr isEqualToString:@"all"]) {
[convertStr appendString:@"全部项目"];
}else if ([keyStr isEqualToString:@"created"]) {
[convertStr appendString:@"我创建的"];
}else if ([keyStr isEqualToString:@"joined"]) {
[convertStr appendString:@"我参与的"];
}else if ([keyStr isEqualToString:@"watched"]) {
[convertStr appendString:@"我关注的"];
}else if ([keyStr isEqualToString:@"stared"]) {
[convertStr appendString:@"我收藏的"];
}else
{
NSLog(@"-------------error type:%@",keyStr);
}
if ([[aDic objectForKey:keyStr] length]>0) {
[convertStr appendString:[NSString stringWithFormat:@" (%@)",[aDic objectForKey:keyStr]]];
}
return [convertStr copy];
}
//更新数据源
-(void)updateDateSource:(ProjectCount*)pCount
{
_items = @[@{@"all":[pCount.all stringValue]},@{@"created":[pCount.created stringValue]},@{@"joined":[pCount.joined stringValue]},@{@"watched":[pCount.watched stringValue]},@{@"stared":[pCount.stared stringValue]}].mutableCopy;
}
//转化为Projects类对应类型
-(NSInteger)convertToProjectType
{
switch (_selectNum) {
case 0:
return ProjectsTypeAll;
break;
case 1:
return ProjectsTypeCreated;
break;
case 2:
return ProjectsTypeJoined;
break;
case 3:
return ProjectsTypeWatched;
break;
case 4:
return ProjectsTypeStared;
break;
default:
NSLog(@"type error");
return ProjectsTypeAll;
break;
}
}
#pragma mark -- uitableviewdelegate & datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
switch (section) {
case 0:
return kfirstRowNum;
break;
case 1:
return 2+1;
break;
case 2:
return 1+1;
break;
default:
return 0;
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
cell.backgroundColor=[UIColor clearColor];
UILabel *titleLab=[[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 50)];
titleLab.font=[UIFont systemFontOfSize:15];
[cell.contentView addSubview:titleLab];
if (indexPath.section==0) {
titleLab.textColor=(indexPath.row==_selectNum)?[UIColor colorWithHexString:@"0x3BBD79"]:[UIColor colorWithHexString:@"0x222222"];
titleLab.text=[self formatTitleStr:[_items objectAtIndex:indexPath.row]];
}else if (indexPath.section==1) {
if(indexPath.row==0){
[titleLab removeFromSuperview];
UIView *seperatorLine=[[UIView alloc] initWithFrame:CGRectMake(20, 15, self.bounds.size.width-40, 0.5)];
seperatorLine.backgroundColor=[UIColor colorWithHexString:@"0xcccccc"];
[cell.contentView addSubview:seperatorLine];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}else{
titleLab.textColor=(indexPath.row+kfirstRowNum==_selectNum)?[UIColor colorWithHexString:@"0x3BBD79"]:[UIColor colorWithHexString:@"0x222222"];
titleLab.text=[self formatTitleStr:[_items objectAtIndex:3+indexPath.row-1]];
}
}else
{
if(indexPath.row==0){
[titleLab removeFromSuperview];
UIView *seperatorLine=[[UIView alloc] initWithFrame:CGRectMake(20, 15, self.bounds.size.width-40, 0.5)];
seperatorLine.backgroundColor=[UIColor colorWithHexString:@"0xcccccc"];
[cell.contentView addSubview:seperatorLine];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}else{
[titleLab setX:45];
titleLab.textColor=[UIColor colorWithHexString:@"0x727f8d"];
titleLab.text=@"项目广场";
UIImageView *projectSquareIcon=[[UIImageView alloc] initWithFrame:CGRectMake(20, 25-8, 16, 16)];
projectSquareIcon.image=[UIImage imageNamed:@"fliter_square"];
[cell.contentView addSubview:projectSquareIcon];
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return ((indexPath.row==0)&&(indexPath.section==1))||((indexPath.row==0)&&(indexPath.section==2))?30.5:50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
_selectNum=indexPath.row;
[self dismissMenu];
_clickBlock([self convertToProjectType]);
}else if (indexPath.section==1) {
if(indexPath.row==0){
_closeBlock();
return;
}
_selectNum=indexPath.row+kfirstRowNum-1;
[self dismissMenu];
_clickBlock([self convertToProjectType]);
}else
{
if(indexPath.row==0){
_closeBlock();
return;
}
_clickBlock(1000);
_closeBlock();
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didClickedContentView:(UIGestureRecognizer *)sender {
_closeBlock();
}
@end