FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AppDevKit/AppDevKit/PullToRefreshExampleViewController.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
/
PullToRefreshExampleViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
180 lines (146 loc) · 7.72 KB
Breadcrumbs
AppDevKit
/
AppDevKit
/
PullToRefreshExampleViewController.m
Copy path
File metadata and controls
180 lines (146 loc) · 7.72 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
//
//
PullToRefreshExampleViewController.m
//
AppDevKit
//
//
Created by Jeff Lin on 12/6/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
"
PullToRefreshExampleViewController.h
"
#
import
"
AppDevKit.h
"
#
import
"
UIColor+ThemeColor.h
"
#
import
"
SampleVCollectionViewCell.h
"
#
import
"
PullToRefreshHelpView.h
"
#
import
"
InfiniteScrollingHelpView.h
"
static
NSString
*
const
CellCollectionViewCellIdentifier =
@"
SampleVCollectionViewCell
"
;
@interface
PullToRefreshExampleViewController
() <UICollectionViewDataSource, UICollectionViewDelegate>
@property
(
weak
,
nonatomic
)
IBOutlet
UICollectionView *collectionView;
@property
(
strong
,
nonatomic
)
NSMutableArray
*flagArray;
@end
@implementation
PullToRefreshExampleViewController
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
//
Do any additional setup after loading the view from its nib.
[
self
setupView
];
}
- (
void
)
didMoveToParentViewController
:
(UIViewController *)
parent
{
[
super
didMoveToParentViewController:
parent];
if
(!parent) {
return
;
}
[
self
setupPullToRefreshView
];
[
self
setupInfiniteScrollingView
];
}
- (
void
)
didReceiveMemoryWarning
{
[
super
didReceiveMemoryWarning
];
//
Dispose of any resources that can be recreated.
}
- (
void
)
setupView
{
self.
title
=
@"
Pull to refresh + infinite scroll
"
;
NSString
*plistPath = [[
NSBundle
mainBundle
]
pathForResource:
@"
Country-data
"
ofType:
@"
plist
"
];
self.
flagArray
= [[
NSArray
arrayWithContentsOfFile:
plistPath]
mutableCopy
];
UINib *cellNib = [UINib
nibWithNibName:
CellCollectionViewCellIdentifier
bundle:
nil
];
[
self
.collectionView
registerNib:
cellNib
forCellWithReuseIdentifier:
CellCollectionViewCellIdentifier];
self.
collectionView
.
delegate
= self;
self.
collectionView
.
dataSource
= self;
self.
collectionView
.
backgroundColor
= [UIColor
themeBackgroundColor
];
UIBarButtonItem *layoutBarButtonItem = [[UIBarButtonItem
alloc
]
initWithBarButtonSystemItem:
UIBarButtonSystemItemEdit
target:
self
action:
@selector
(
layoutSwitchHandler
)];
self.
navigationItem
.
rightBarButtonItem
= layoutBarButtonItem;
}
- (
void
)
setupPullToRefreshView
{
PullToRefreshHelpView *refreshView = [[PullToRefreshHelpView
alloc
]
initWithFrame:
CGRectMake
(
0
.
0f
,
0
.
0f
,
self
.view.frame.size.width,
60
.
0f
)];
__weak PullToRefreshExampleViewController *weakSelf = self;
[
self
.collectionView
ADKAddPullToRefreshWithHandleView:
refreshView
actionHandler:
^{
//
Delay 3s, for show animation
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
, (
int64_t
)(
3
.
0f
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(), ^{
NSString
*plistPath = [[
NSBundle
mainBundle
]
pathForResource:
@"
Country-data
"
ofType:
@"
plist
"
];
weakSelf.
flagArray
= [[
NSArray
arrayWithContentsOfFile:
plistPath]
mutableCopy
];
[weakSelf.collectionView
reloadData
];
[weakSelf.collectionView.pullToRefreshContentView
stopAnimating
];
});
}];
self.
collectionView
.
pullToRefreshContentView
.
autoFadeEffect
=
YES
;
}
- (
void
)
setupInfiniteScrollingView
{
InfiniteScrollingHelpView *infiniteScrollView = [[InfiniteScrollingHelpView
alloc
]
initWithFrame:
CGRectMake
(
0
.
0f
,
0
.
0f
,
self
.view.frame.size.width,
60
.
0f
)];
__weak PullToRefreshExampleViewController *weakSelf = self;
[
self
.collectionView
ADKAddInfiniteScrollingWithHandleView:
infiniteScrollView
actionHandler:
^{
//
Delay 1s, for show animation
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
, (
int64_t
)(
3
.
0f
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(), ^{
NSString
*plistPath = [[
NSBundle
mainBundle
]
pathForResource:
@"
Country-data
"
ofType:
@"
plist
"
];
[weakSelf.flagArray
addObjectsFromArray:
[
NSArray
arrayWithContentsOfFile:
plistPath]];
[weakSelf.collectionView
reloadData
];
[weakSelf.collectionView.infiniteScrollingContentView
stopAnimating
];
});
}];
self.
collectionView
.
infiniteScrollingContentView
.
autoFadeEffect
=
YES
;
}
- (
void
)
layoutSwitchHandler
{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:
@"
Layout Change Notice
"
message:
@"
Simulating layout change when keyboard is appeared. Please scroll to bottom to see the effect. Using ADKUpdateInfiniteScrollingLayout to update layout manually.
"
preferredStyle:
UIAlertControllerStyleAlert];
UIAlertAction *closeAlertAction = [UIAlertAction
actionWithTitle:
@"
OK
"
style:
UIAlertActionStyleDefault
handler:
^(UIAlertAction * _Nonnull action) {
//
Simulating layout change when keyboard is appeared and need to adjust contentInsets.
UIEdgeInsets newContentInset = self.
collectionView
.
contentInset
;
newContentInset.
bottom
=
235
.
0f
;
self.
collectionView
.
contentInset
= newContentInset;
[
self
.collectionView
ADKUpdateInfiniteScrollingLayout
];
}];
[alertController
addAction:
closeAlertAction];
[
self
presentViewController:
alertController
animated:
YES
completion:
^{
//
Do nothing
}];
}
#
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
;
cell = [collectionView
dequeueReusableCellWithReuseIdentifier:
CellCollectionViewCellIdentifier
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];
}
@end
Back
|
FazBrowse Home
|
New Git URL