FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Views/ScreenView.m at master · magic-coder/Coding-iOS · GitHub
magic-coder
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
ScreenView.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
273 lines (214 loc) · 8.63 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
ScreenView.m
Copy path
File metadata and controls
273 lines (214 loc) · 8.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
ScreenView.m
//
Coding_iOS
//
//
Created by 张达棣 on 16/12/7.
//
Copyright © 2016年 Coding. All rights reserved.
//
#
import
"
ScreenView.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
TaskSelectionCell.h
"
#
import
"
ScreenCell.h
"
#
define
KMainLeftWith
45
@interface
ScreenView
()<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property
(
nonatomic
,
strong
) UITableView *tableView;
@property
(
nonatomic
,
assign
)
NSInteger
selectNum;
//
选中数据
@property
(
nonatomic
,
strong
) UISearchBar *searchBar;
@property
(
nonatomic
,
strong
) UIView *mainView;
@end
@implementation
ScreenView
#
pragma mark
- 生命周期方法
- (
instancetype
)
initWithFrame
:
(CGRect)
frame
{
self = [
super
initWithFrame:
frame];
if
(self) {
[
self
creatView
];
}
return
self;
}
#
pragma mark
- 外部方法
+ (
instancetype
)
creat
{
ScreenView *screenView = [[ScreenView
alloc
]
initWithFrame:
CGRectMake
(
0
,
0
,
kScreen_Width
,
kScreen_Height
)];
screenView.
hidden
=
YES
;
[
kKeyWindow
addSubview:
screenView];
return
screenView;
}
- (
void
)
showOrHide
{
if
(self.
hidden
) {
[
self
show
];
}
else
{
[
self
hide
];
}
}
#
pragma
makr - 消息
#
pragma mark
- 系统委托
#
pragma mark
UITableViewDataSource
- (
NSInteger
)
numberOfSectionsInTableView
:
(UITableView *)
tableView
{
return
1
;
}
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
return
_labels.
count
+ _tastArray.
count
;
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
if
(indexPath.
row
< _tastArray.
count
) {
TaskSelectionCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_TaskSelectionCell
forIndexPath:
indexPath];
cell.
title
= _tastArray[indexPath.row];
cell.
isSel
= indexPath.
row
== _selectNum;
cell.
isShowLine
= indexPath.
row
== _tastArray.
count
-
1
;
return
cell;
}
else
{
ScreenCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_ScreenCell
forIndexPath:
indexPath];
cell.
color
= _labels[indexPath.row - _tastArray.count][
@"
color
"
];
cell.
title
= _labels[indexPath.row - _tastArray.count][
@"
name
"
];
cell.
isSel
= indexPath.
row
== _selectNum;
return
cell;
}
}
#
pragma mark
UITableViewDelegate
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
[tableView
deselectRowAtIndexPath:
indexPath
animated:
YES
];
self.
keyword
=
nil
;
_searchBar.
text
=
nil
;
_selectNum = indexPath.
row
;
[tableView
reloadData
];
if
(indexPath.
row
< _tastArray.
count
) {
self.
label
=
nil
;
self.
status
= [
NSString
stringWithFormat:
@"
%ld
"
, indexPath.row +
1
];
}
else
{
self.
status
=
nil
;
self.
label
= _labels[indexPath.row - _tastArray.count][
@"
name
"
];
}
[
self
clickDis
];
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
return
50
;
}
- (
void
)
scrollViewWillBeginDragging
:
(UIScrollView *)
scrollView
{
[
self
.searchBar
resignFirstResponder
];
}
#
pragma mark
UISearchBarDelegate
- (
void
)
searchBarSearchButtonClicked
:
(UISearchBar *)
searchBar
{
self.
keyword
= _searchBar.
text
;
[
self
clickDis
];
}
#
pragma mark
- 自定义委托
#
pragma mark
- 响应方法
#
pragma mark
- 私有方法
- (
void
)
creatView
{
self.
hidden
=
YES
;
self.
backgroundColor
= [UIColor
colorWithRed:
0
/
255.0
green:
0
/
255.0
blue:
0
/
255.0
alpha:
.
5
];
_selectNum = -
1
;
UIButton *bgButton = [[UIButton
alloc
]
init
];
[bgButton
addTarget:
self
action:
@selector
(
hide
)
forControlEvents:
UIControlEventTouchDown];
[
self
addSubview:
bgButton];
bgButton.
sd_layout
.
leftSpaceToView
(self,
0
).
topEqualToView
(self).
bottomEqualToView
(self).
rightEqualToView
(self);
UIView *mainView = [[UIView
alloc
]
init
];
mainView.
backgroundColor
= [UIColor
whiteColor
];
[
self
addSubview:
mainView];
mainView.
sd_layout
.
leftSpaceToView
(self, KMainLeftWith).
topSpaceToView
(self,
0
).
bottomEqualToView
(self).
rightEqualToView
(self);
_mainView = mainView;
UISearchBar *searchBar = [[UISearchBar
alloc
]
init
];
UITextField *searchField = [searchBar
valueForKey:
@"
searchField
"
];
searchField.
backgroundColor
= [UIColor
clearColor
];
searchField.
borderStyle
= UITextBorderStyleNone;
searchField.
placeholder
=
@"
查找相关任务
"
;
searchBar.
barTintColor
= [UIColor
colorWithRGBHex:
0xf0f2f5
];
searchBar.
cornerRadius
=
4
;
searchBar.
masksToBounds
=
YES
;
searchBar.
returnKeyType
= UIReturnKeySearch;
searchBar.
delegate
= self;
[mainView
addSubview:
searchBar];
searchBar.
sd_layout
.
leftSpaceToView
(mainView,
15
).
topSpaceToView
(mainView,
15
+
kSafeArea_Top
).
rightSpaceToView
(mainView,
15
).
heightIs
(
31
);
_searchBar = searchBar;
UIButton *resetButton = [[UIButton
alloc
]
init
];
[resetButton
setTitle:
@"
重置
"
forState:
UIControlStateNormal];
[resetButton
setTitleColor:
[UIColor
colorWithRGBHex:
0x222222
]
forState:
UIControlStateNormal];
resetButton.
titleLabel
.
font
= [UIFont
systemFontOfSize:
15
];
resetButton.
backgroundColor
= [UIColor
whiteColor
];
[resetButton
addTarget:
self
action:
@selector
(
resetButtonClick
)
forControlEvents:
UIControlEventTouchUpInside];
[mainView
addSubview:
resetButton];
resetButton.
sd_layout
.
leftSpaceToView
(mainView,
0
).
bottomSpaceToView
(mainView,
kSafeArea_Bottom
).
rightSpaceToView
(mainView,
0
).
heightIs
(
48.5
);
UILabel *line = [[UILabel
alloc
]
init
];
line.
backgroundColor
=
kColorDDD
;
[mainView
addSubview:
line];
line.
sd_layout
.
leftSpaceToView
(mainView,
0
).
rightSpaceToView
(mainView,
0
).
bottomSpaceToView
(resetButton,
0
).
heightIs
(.
5
);
UITableView *tableView = [[UITableView
alloc
]
init
];
tableView.
backgroundColor
= [UIColor
clearColor
];
tableView.
backgroundView
=
nil
;
tableView.
dataSource
= self;
tableView.
delegate
= self;
tableView.
tableFooterView
= [[UIView
alloc
]
init
];
tableView.
separatorStyle
= UITableViewCellSeparatorStyleNone;
[tableView
registerClass:
[UITableViewCell
class
]
forCellReuseIdentifier:
@"
zcell
"
];
[tableView
registerClass:
[TaskSelectionCell
class
]
forCellReuseIdentifier:
kCellIdentifier_TaskSelectionCell
];
[tableView
registerClass:
[ScreenCell
class
]
forCellReuseIdentifier:
kCellIdentifier_ScreenCell
];
[mainView
addSubview:
tableView];
tableView.
sd_layout
.
leftSpaceToView
(mainView,
0
).
topSpaceToView
(searchBar,
0
).
bottomSpaceToView
(resetButton,
0
).
rightEqualToView
(mainView);
_tableView = tableView;
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer
alloc
]
initWithTarget:
self
action:
@selector
(
handlePan:
)];
[
self
addGestureRecognizer:
panGestureRecognizer];
}
- (
void
)
clickDis
{
[
self
hide
];
if
(_selectBlock) {
_selectBlock
(_keyword, _status, _label);
}
}
- (
void
)
resetButtonClick
{
[
self
hide
];
_keyword = _status = _label =
nil
;
_selectNum = -
1
;
_searchBar.
text
=
nil
;
[_tableView
reloadData
];
if
(_selectBlock) {
_selectBlock
(_keyword, _status, _label);
}
}
#
pragma mark
- get/set方法
- (
void
)
show
{
if
(![_searchBar.text
isEqualToString:
_keyword]) {
_searchBar.
text
= _keyword;
}
_mainView.
x
=
kScreen_Width
- KMainLeftWith;
self.
backgroundColor
= [UIColor
colorWithRed:
0
/
255.0
green:
0
/
255.0
blue:
0
/
255.0
alpha:
.
5
];
self.
hidden
=
NO
;
[UIView
animateWithDuration:
.
3
animations:
^{
self.
alpha
=
1
;
_mainView.
x
= KMainLeftWith;
}];
}
- (
void
)
hide
{
[
self
.searchBar
resignFirstResponder
];
[UIView
animateWithDuration:
.
3
animations:
^{
self.
alpha
=
0
;
_mainView.
x
+= (
kScreen_Width
- KMainLeftWith);
}
completion:
^(
BOOL
finished) {
self.
hidden
=
YES
;
}];
}
- (
void
)
handlePan
:
(UIPanGestureRecognizer*)
recognizer
{
[_searchBar
resignFirstResponder
];
CGPoint translation = [recognizer
translationInView:
_mainView];
if
(_mainView.
x
+ translation.
x
> KMainLeftWith) {
_mainView.
x
+= translation.
x
;
[recognizer
setTranslation:
CGPointZero
inView:
_mainView];
}
else
{
_mainView.
x
= KMainLeftWith;
}
CGFloat alpha = .
5
;
alpha -= (_mainView.
x
/
kScreen_Width
* alpha);
self.
backgroundColor
= [UIColor
colorWithRed:
0
/
255.0
green:
0
/
255.0
blue:
0
/
255.0
alpha:
alpha];
if
(recognizer.
state
== UIGestureRecognizerStateEnded) {
[
self
hide
];
}
}
- (
void
)
setTastArray
:
(
NSArray
*)
tastArray
{
_tastArray = tastArray;
[_tableView
reloadData
];
}
- (
void
)
setLabels
:
(
NSArray
*)
labels
{
_labels = labels;
[_tableView
reloadData
];
}
@end
Back
|
FazBrowse Home
|
New Git URL