-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewController.m
More file actions
229 lines (163 loc) · 8.19 KB
/
Copy pathViewController.m
File metadata and controls
229 lines (163 loc) · 8.19 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
//
// ViewController.m
// DropMenuDemo
//
// Created by 魏小庄 on 2018/7/3.
// Copyright © 2018年 魏小庄. All rights reserved.
//
#import "ViewController.h"
#import "MoreFilterView.h"
#import "DropMenuBar.h"
#import "MenuAction.h"
#import "ItemModel.h"
@interface ViewController () <DropMenuBarDelegate>
@property (nonatomic, strong) DropMenuBar *menuScreeningView; //条件选择器
@property (nonatomic, strong) MoreFilterView *filterView;
@property (nonatomic, strong) NSMutableArray *oneList;
@property (nonatomic, strong) NSMutableArray *twoList;
@property (nonatomic, strong) NSMutableArray *threeuList;
@property (nonatomic, weak) MenuAction *customAction;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.oneList = [NSMutableArray arrayWithCapacity:0];
self.twoList = [NSMutableArray arrayWithCapacity:0];
self.threeuList = [NSMutableArray arrayWithCapacity:0];
[self creatData];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0 green:145.0f/255.0f blue:67.0f/255.0f alpha:1.000];
self.view.backgroundColor = [UIColor yellowColor];
MenuAction *one = [MenuAction actionWithTitle:@"one" style:MenuActionTypeList];
// one.ListDataSource = self.oneList;
one.didSelectedMenuResult = ^(NSInteger index, ItemModel *selecModel) {
NSLog(@"1111 === %@", selecModel.displayText);
};
MenuAction *two = [MenuAction actionWithTitle:@"two" style:MenuActionTypeList];
two.ListDataSource = self.twoList;
two.didSelectedMenuResult = ^(NSInteger index, ItemModel *selecModel) {
NSLog(@"2222 ==== %@", selecModel.displayText);
};
MenuAction *three = [MenuAction actionWithTitle:@"three" style:MenuActionTypeList];
three.ListDataSource = self.threeuList;
three.didSelectedMenuResult = ^(NSInteger index, ItemModel *selecModel) {
NSLog(@"3333 ==== %@", selecModel.displayText);
};
MenuAction *custom = [MenuAction actionWithTitle:@"自定义" style:MenuActionTypeCustom];
__weak typeof(self) weakSelf = self;
custom.displayCustomWithMenu = ^UIView *{
return weakSelf.filterView;
};
self.customAction = custom;
self.menuScreeningView = [[DropMenuBar alloc] initWithAction:@[one, two,three, custom]];
self.menuScreeningView.delegate = self;
self.menuScreeningView.frame = CGRectMake(20, 64, self.view.frame.size.width - 40, 45);
self.menuScreeningView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.menuScreeningView];
// Do any additional setup after loading the view, typically from a nib.
}
- (UIImage *)drawTriangleWithFront:(BOOL)front {
UIView *triangleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
triangleView.backgroundColor = [UIColor clearColor];
CAShapeLayer *triangleLayer = [[CAShapeLayer alloc]init];
UIBezierPath *path = [UIBezierPath bezierPath];
if (front) {
[path moveToPoint:CGPointMake(20, 20)];
[path addLineToPoint:CGPointMake(15, 15)];
[path addLineToPoint:CGPointMake(10, 20)];
triangleLayer.path = path.CGPath;
[triangleView.layer addSublayer:triangleLayer];
[triangleLayer setFillColor:[UIColor yellowColor].CGColor];
}else {
[path moveToPoint:CGPointMake(20, 20)];
[path addLineToPoint:CGPointMake(25, 25)];
[path addLineToPoint:CGPointMake(30, 20)];
triangleLayer.path = path.CGPath;
[triangleView.layer addSublayer:triangleLayer];
[triangleLayer setFillColor:[UIColor redColor].CGColor];
}
UIGraphicsBeginImageContextWithOptions(triangleView.frame.size, YES, [UIScreen mainScreen].scale); //图形上下文设置
[triangleView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();//赋值
UIGraphicsEndImageContext();//结束
return image;
}
- (void)creatData {
for (int i = 0; i < 15; i++) {
BOOL select = i == 0;
ItemModel *model = [ItemModel modelWithText:[NSString stringWithFormat:@" == %d", i] currentID:[NSString stringWithFormat:@"%d", i] isSelect:select];
[self.oneList addObject:model];
}
// 两级列表
for (int i = 0; i < 15; i++) {
ItemModel *model;
if(i != 0) {
model = [ItemModel modelWithText:[NSString stringWithFormat:@" <=> %d", i] currentID:[NSString stringWithFormat:@"%d", i] isSelect:i == 0];
NSMutableArray *temp = [NSMutableArray array];
for (int j = 0; j < 10; j++) {
ItemModel *layerModel = [ItemModel modelWithText:[NSString stringWithFormat:@"%d $$ %d",i, j] currentID:[NSString stringWithFormat:@"%d", j] isSelect:j == 0];
[temp addObject:layerModel];
}
model.dataSource = temp;
}else {
model = [ItemModel modelWithText:[NSString stringWithFormat:@"不限"] currentID:[NSString stringWithFormat:@"%d", i] isSelect:i == 0];
}
[self.twoList addObject:model];
}
// 三级列表
for (int i = 0; i < 15; i++) {
ItemModel *model;
if(i == 0) {
model = [ItemModel modelWithText:[NSString stringWithFormat:@"不限"] currentID:[NSString stringWithFormat:@"%d", i] isSelect:i == 0];
}else {
model = [ItemModel modelWithText:[NSString stringWithFormat:@" <一级> %d", i] currentID:[NSString stringWithFormat:@"%d", i] isSelect:i == 0];
NSMutableArray *temp = [NSMutableArray array];
for (int j = 0; j < 10; j++) {
ItemModel *layerModel;
if (j == 0) {
layerModel = [ItemModel modelWithText:[NSString stringWithFormat:@"不限"] currentID:[NSString stringWithFormat:@"%d", j] isSelect:j == 0];
}else {
layerModel = [ItemModel modelWithText:[NSString stringWithFormat:@"%d 二级 %d",i, j] currentID:[NSString stringWithFormat:@"%d", j] isSelect:j == 0];
NSMutableArray *temp = [NSMutableArray arrayWithCapacity:0];
for (int x = 0; x < 12; x++) {
ItemModel *layerModel;
if (x == 0) {
layerModel = [ItemModel modelWithText:[NSString stringWithFormat:@"不限"] currentID:[NSString stringWithFormat:@"%d", x] isSelect:x == 0];
}else {
layerModel = [ItemModel modelWithText:[NSString stringWithFormat:@"%d 三级 %d",j, x] currentID:[NSString stringWithFormat:@"%d", x] isSelect:x == 0];
}
[temp addObject:layerModel];
}
layerModel.dataSource = temp;
}
[temp addObject:layerModel];
}
model.dataSource = temp;
}
[self.threeuList addObject:model];
}
}
#pragma mark - DropMenuBarDelegate
- (void)dropMenuViewWillAppear:(DropMenuBar *)view selectAction:(MenuAction *)action {
NSLog(@"即将显示");
if ([action.title isEqualToString:@"one"]) {
// 模拟每次点击时重新获取最新数据 网络请求返回数据
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
action.ListDataSource = self.oneList;
[self.menuScreeningView reloadMenus];
});
}
}
- (void)dropMenuViewWillDisAppear:(DropMenuBar *)view selectAction:(MenuAction *)action {
NSLog(@"即将消失");
}
- (MoreFilterView *)filterView {
if (!_filterView) {
_filterView = [MoreFilterView loadFilterView];
__weak typeof(self) weakSelf = self;
_filterView.didConfirmClick = ^(NSString *title) {
[weakSelf.customAction adjustTitle:title textColor:[UIColor orangeColor]];
};
}
return _filterView;
}
@end