-
Notifications
You must be signed in to change notification settings - Fork 8
/
industry.m
219 lines (161 loc) · 6.89 KB
/
industry.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
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
//
// industry.m
// collection_master
//
// Created by 是 撒 on 5/18/15.
// Copyright (c) 2015 芳仔小脚丫. All rights reserved.
//
#import "industry.h"
#import "industry_cell.h"
@implementation industry
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)initWithlist:(CGFloat)height{
/**
* 绑定本地数据(行业领域)
*/
// 读取本地资源文件保存数组
NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"industry.plist" ofType:nil];
industry_kind = [NSArray arrayWithContentsOfFile:fullpath];
self = [super init];
if(self){
self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
self.backgroundColor = RGBACOLOR(160, 160, 160, 0);
title = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenHeight, ScreenWidth, 30)];
[title setText:@" 行业领域"];
title.font = [UIFont systemFontOfSize:12];
[title setTextColor:[UIColor colorWithRed:0.0/255 green:161.0/255 blue:233.0/255 alpha:1.0f]];
[title setBackgroundColor:[UIColor colorWithRed:222.0/255 green:251.0/255 blue:255.0/255 alpha:1.0f]];
// 设置collectionview
identifier = @"cell";
// 初始化layout
UICollectionViewFlowLayout * flowLayout =[[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
_collectionView =[[UICollectionView alloc] initWithFrame:CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight/2)collectionViewLayout:flowLayout];
[_collectionView setBackgroundColor:[UIColor whiteColor]];
//注册单元格
[_collectionView registerClass:[industry_cell class]forCellWithReuseIdentifier:identifier];
//设置代理
_collectionView.delegate = self;
_collectionView.dataSource = self;
//代码控制header和footer的显示
UICollectionViewFlowLayout *collectionViewLayout = (UICollectionViewFlowLayout *)_collectionView.collectionViewLayout;
collectionViewLayout.headerReferenceSize = CGSizeMake(ScreenWidth, 20);
[self addSubview:title];
[self addSubview:_collectionView];
[self animeData];
}
return self;
}
-(void)animeData{
//self.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedCancel)];
[self addGestureRecognizer:tapGesture];
tapGesture.delegate = (id)self;
[UIView animateWithDuration:.25 animations:^{
self.backgroundColor = RGBACOLOR(160, 160, 160, .4);
[UIView animateWithDuration:.25 animations:^{
[title setFrame:CGRectMake(title.frame.origin.x, (ScreenHeight-_collectionView.frame.size.height)-(title.frame.size.height)-40, title.frame.size.width, title.frame.size.height)];
[_collectionView setFrame:CGRectMake(_collectionView.frame.origin.x, ScreenHeight-_collectionView.frame.size.height-40, _collectionView.frame.size.width, _collectionView.frame.size.height)];
}];
} completion:^(BOOL finished) {
}];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if([touch.view isKindOfClass:[self class]]){
return YES;
}
return NO;
}
-(void)tappedCancel{
[UIView animateWithDuration:.25 animations:^{
[_collectionView setFrame:CGRectMake(0, ScreenHeight, ScreenWidth, 0)];
[title setFrame:CGRectMake(0, ScreenHeight, ScreenHeight, 0)];
self.alpha = 0;
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
}
}];
}
- (void)showInView:(UIViewController *)Sview
{
if(Sview==nil){
[[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:self];
}else{
[Sview.view addSubview:self];
}
}
#pragma mark - collectionView delegate
//设置分区
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
//每个分区上得元素个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return industry_kind.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
industry_cell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell sizeToFit];
[cell setIsAccessibilityElement:YES];
cell.backgroundColor =[UIColor whiteColor];
NSDictionary *rowDict = [industry_kind objectAtIndex:row];
[cell.industry setText:[rowDict objectForKey:@"data"]];
return cell;
}
// 设置点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
industry_cell * cell = (industry_cell *)[collectionView cellForItemAtIndexPath:indexPath];
NSLog(@"%@",cell.industry.text);
if([_delegate respondsToSelector:@selector(didSelect:)]){
NSLog(@"test111");
}
if(_delegate!=nil && [_delegate respondsToSelector:@selector(didSelect:)]){
[_delegate didSelect:cell.industry.text];
return;
}// if(cell.selected){
// cell.industry.textColor = [UIColor colorWithRed:89.0/255 green:186.0/255 blue:239.0/255 alpha:1.0f];
// }else{
// //self.backgroundColor = [UIColor redColor];
//
// cell.industry.textColor = [UIColor blackColor];
// }
[self tappedCancel];
}
//设置元素的的大小框
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
UIEdgeInsets top = {0,0,0,0};
return top;
}
// 定义上下cell的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
// 定义左右cell的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
//设置元素大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(ScreenWidth/3, 45);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end