-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSStickyParallaxHeaderViewController.m
More file actions
128 lines (95 loc) · 4.16 KB
/
CSStickyParallaxHeaderViewController.m
File metadata and controls
128 lines (95 loc) · 4.16 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
//
// CSStickyParallaxHeaderViewController.m
// CSStickyHeaderFlowLayoutDemo
//
// Created by James Tang on 6/4/14.
// Copyright (c) 2014 Jamz Tang. All rights reserved.
//
#import "CSStickyParallaxHeaderViewController.h"
#import "CSCell.h"
#import "CSStickyHeaderFlowLayout.h"
@interface CSStickyParallaxHeaderViewController ()
@property (nonatomic, strong) NSArray *sections;
@property (nonatomic, strong) UINib *headerNib;
@end
@implementation CSStickyParallaxHeaderViewController
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.sections = @[
@[
@"Song 1",
@"Song 2",
@"Song 3",
@"Song 4",
@"Song 5",
@"Song 6",
@"Song 7",
@"Song 8",
@"Song 9",
@"Song 10",
@"Song 11",
@"Song 12",
@"Song 13",
@"Song 14",
@"Song 15",
@"Song 16",
@"Song 17",
@"Song 18",
@"Song 19",
@"Song 20",
],
];
self.headerNib = [UINib nibWithNibName:@"CSAlwaysOnTopHeader" bundle:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
layout.parallaxHeaderReferenceSize = CGSizeMake(320, 426);
layout.parallaxHeaderMinimumReferenceSize = CGSizeMake(320, 110);
layout.parallaxHeaderAlwaysOnTop = YES;
// If we want to disable the sticky header effect
layout.disableStickyHeaders = YES;
}
// Also insets the scroll indicator so it appears below the search bar
self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[self.collectionView registerNib:self.headerNib
forSupplementaryViewOfKind:CSStickyHeaderParallaxHeader
withReuseIdentifier:@"header"];
}
#pragma mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return [self.sections count];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.sections[section] count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *obj = self.sections[indexPath.section][indexPath.row];
CSCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell"
forIndexPath:indexPath];
cell.textLabel.text = obj;
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
CSCell *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"sectionHeader"
forIndexPath:indexPath];
return cell;
} else if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {
UICollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"header"
forIndexPath:indexPath];
return cell;
}
return nil;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end