FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AppDevKit/AppDevKit/ViewAutoLayoutSupportViewController.m at master · yahoo/AppDevKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
yahoo
/
AppDevKit
Public
Notifications
You must be signed in to change notification settings
Fork
153
Star
1.4k
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
AppDevKit
/
AppDevKit
/
ViewAutoLayoutSupportViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
229 lines (176 loc) · 8.08 KB
Breadcrumbs
AppDevKit
/
AppDevKit
/
ViewAutoLayoutSupportViewController.m
Copy path
File metadata and controls
229 lines (176 loc) · 8.08 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
//
//
UIViewAutoLayoutSupportViewController.m
//
AppDevKit
//
//
Created by Chih Feng Sung on 6/9/15.
//
Copyright © 2015, Yahoo Inc.
//
Licensed under the terms of the BSD License.
//
Please see the LICENSE file in the project root for terms.
//
#
import
"
ViewAutoLayoutSupportViewController.h
"
#
import
"
AppDevKit.h
"
#
import
"
UIColor+ThemeColor.h
"
#
import
"
AvatorCollectionViewCell.h
"
#
import
"
SampleVCollectionViewCell.h
"
#
import
"
ModalViewController.h
"
static
NSString
*
const
AvatorCellCollectionViewCellIdentifier =
@"
AvatorCollectionViewCell
"
;
static
NSString
*
const
CellCollectionViewCellIdentifier =
@"
SampleVCollectionViewCell
"
;
@interface
ViewAutoLayoutSupportViewController
() <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, ADKModalMaskViewDelegate>
@property
(
weak
,
nonatomic
)
IBOutlet
UICollectionView *avatorCollectionView;
@property
(
weak
,
nonatomic
)
IBOutlet
UICollectionView *demoCollectionView;
@property
(
strong
,
nonatomic
)
NSArray
*flagArray;
@property
(
strong
,
nonatomic
) ADKModalMaskView *modalView;
@property
(
strong
,
nonatomic
) ModalViewController *modalController;
@property
(
weak
,
nonatomic
)
IBOutlet
UISegmentedControl *typeSegmentedControl;
- (
IBAction
)
typeChangedHandler
;
@end
@implementation
ViewAutoLayoutSupportViewController
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
[
self
setupView
];
}
- (
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
//
Dispose of any resources that can be recreated.
}
- (
void
)
setupView
{
self.
title
=
@"
UIView+ADKAutoLayoutSupport
"
;
self.
view
.
backgroundColor
= [UIColor
blackColor
];
self.
typeSegmentedControl
.
tintColor
= [UIColor
ADKColorWithHexString:
@"
CCCCCC
"
];
self.
edgesForExtendedLayout
= UIRectEdgeNone;
self.
avatorCollectionView
.
contentInsetAdjustmentBehavior
= UIScrollViewContentInsetAdjustmentNever;
NSString
*plistPath = [[
NSBundle
mainBundle
]
pathForResource:
@"
Country-data
"
ofType:
@"
plist
"
];
self.
flagArray
= [
NSArray
arrayWithContentsOfFile:
plistPath];
UINib *avatorCellNib = [UINib
nibWithNibName:
AvatorCellCollectionViewCellIdentifier
bundle:
nil
];
[
self
.avatorCollectionView
registerNib:
avatorCellNib
forCellWithReuseIdentifier:
AvatorCellCollectionViewCellIdentifier];
self.
avatorCollectionView
.
dataSource
= self;
self.
avatorCollectionView
.
backgroundColor
= [UIColor
themeBackgroundColor
];
UINib *cellNib = [UINib
nibWithNibName:
CellCollectionViewCellIdentifier
bundle:
nil
];
[
self
.demoCollectionView
registerNib:
cellNib
forCellWithReuseIdentifier:
CellCollectionViewCellIdentifier];
self.
demoCollectionView
.
delegate
= self;
self.
demoCollectionView
.
dataSource
= self;
self.
demoCollectionView
.
backgroundColor
= [UIColor
themeBackgroundColor
];
self.
automaticallyAdjustsScrollViewInsets
=
NO
;
}
#
pragma mark
- Event handlers
- (
void
)
typeChangedHandler
{
if
(self.
typeSegmentedControl
.
selectedSegmentIndex
==
0
) {
//
[self.avatorCollectionView ADKUnhideViewHeight];
//
[self.demoCollectionView ADKUnhideTopConstraint];
[
self
.avatorCollectionView
ADKHideView:
NO
withConstraints:
ADKLayoutAttributeHeight | ADKLayoutAttributeTop];
}
else
{
//
[self.avatorCollectionView hideViewHeight];
//
[self.demoCollectionView hideTopConstraint];
[
self
.avatorCollectionView
ADKHideView:
YES
withConstraints:
ADKLayoutAttributeHeight | ADKLayoutAttributeTop];
}
}
#
pragma mark
- UICollectionView delegate methods
- (
NSInteger
)
numberOfSectionsInCollectionView
:
(UICollectionView *)
collectionView
{
return
1
;
}
- (
NSInteger
)
collectionView
:
(UICollectionView *)
collectionView
numberOfItemsInSection
:
(
NSInteger
)
section
{
return
self.
flagArray
.
count
;
}
- (UICollectionViewCell *)
collectionView
:
(UICollectionView *)
collectionView
cellForItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
UICollectionViewCell *cell =
nil
;
NSString
*identifier;
if
(collectionView == self.
avatorCollectionView
) {
identifier = AvatorCellCollectionViewCellIdentifier;
}
else
{
identifier = CellCollectionViewCellIdentifier;
}
cell = [collectionView
dequeueReusableCellWithReuseIdentifier:
identifier
forIndexPath:
indexPath];
if
(cell) {
NSDictionary
*dict = self.
flagArray
[indexPath.row];
SampleVCollectionViewCell *avengersCell = (SampleVCollectionViewCell *)cell;
avengersCell.
imageView
.
image
= [UIImage
imageNamed:
dict[
@"
photo
"
]];
avengersCell.
titleLabel
.
text
= dict[
@"
title
"
];
avengersCell.
descriptionLabel
.
lineBreakMode
= NSLineBreakByTruncatingTail;
avengersCell.
descriptionLabel
.
numberOfLines
=
2
;
avengersCell.
descriptionLabel
.
text
= dict[
@"
desc
"
];
}
return
cell;
}
- (CGFloat)
collectionView
:
(UICollectionView *)
collectionView
layout
:
(UICollectionViewLayout *)
collectionViewLayout
minimumInteritemSpacingForSectionAtIndex
:
(
NSInteger
)
section
{
return
0
.
0f
;
}
- (CGFloat)
collectionView
:
(UICollectionView *)
collectionView
layout
:
(UICollectionViewLayout *)
collectionViewLayout
minimumLineSpacingForSectionAtIndex
:
(
NSInteger
)
section
{
return
0
.
0f
;
}
- (CGSize)
collectionView
:
(UICollectionView *)
collectionView
layout
:
(UICollectionViewLayout *)
collectionViewLayout
sizeForItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
return
[[ADKNibSizeCalculator
sharedInstance
]
sizeForNibNamed:
CellCollectionViewCellIdentifier
withStyle:
ADKNibFixedHeightScaling];
}
- (
void
)
collectionView
:
(UICollectionView *)
collectionView
didSelectItemAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
NSDictionary
*dict = self.
flagArray
[indexPath.row];
if
(!self.
modalController
) {
self.
modalController
= [[ModalViewController
alloc
]
init
];
}
if
(!self.
modalView
) {
self.
modalView
= [[ADKModalMaskView
alloc
]
initWithView:
self
.modalController.view
modalColor:
[[UIColor
blackColor
]
colorWithAlphaComponent:
0
.
7f
]
autoDismiss:
YES
];
}
self.
modalController
.
imageView
.
image
= [UIImage
imageNamed:
dict[
@"
photo
"
]];
self.
modalController
.
titleLabel
.
text
= dict[
@"
title
"
];
self.
modalController
.
descriptionTextView
.
text
= dict[
@"
desc
"
];
self.
modalView
.
delegate
= self;
[
self
.modalView
showInView:
self
.view
withAnimation:
YES
completion:
^(
BOOL
finished) {
//
no-op
}];
self.
modalController
.
view
.
alpha
=
0
.
0f
;
CGPoint startPoint = self.
modalController
.
view
.
center
;
startPoint.
y
=
CGRectGetMaxY
(
ADKPortraitScreenBoundRect
());
CGPoint endPoint = self.
modalController
.
view
.
center
;
self.
modalController
.
view
.
center
= startPoint;
[UIView
animateWithDuration:
0
.
3f
delay:
0
.
2f
options:
UIViewAnimationOptionCurveEaseOut
animations:
^{
self.
modalController
.
view
.
alpha
=
1
.
0f
;
self.
modalController
.
view
.
center
= endPoint;
}
completion:
^(
BOOL
finished) {
}];
}
#
pragma mark
- ADKModalMaskViewDelegate methods
- (
void
)
maskViewWillAutoDismiss
:
(ADKModalMaskView *)
maskView
{
CGPoint endPoint = self.
modalController
.
view
.
center
;
endPoint.
y
=
CGRectGetMaxY
(
ADKPortraitScreenBoundRect
());
[UIView
animateWithDuration:
0
.
3f
delay:
0
.
0f
options:
UIViewAnimationOptionCurveEaseIn
animations:
^{
self.
modalController
.
view
.
alpha
=
0
.
0f
;
self.
modalController
.
view
.
center
= endPoint;
}
completion:
^(
BOOL
finished) {
}];
}
- (
void
)
maskViewDidAutoDismiss
:
(ADKModalMaskView *)
maskView
{
self.
modalView
=
nil
;
self.
modalController
=
nil
;
}
#
pragma mark
- UIContentContainer delegate methods
- (
void
)
viewWillTransitionToSize
:
(CGSize)
size
withTransitionCoordinator
:
(
id
<UIViewControllerTransitionCoordinator>)
coordinator
{
[
self
.demoCollectionView.collectionViewLayout
invalidateLayout
];
}
@end
Back
|
FazBrowse Home
|
New Git URL