-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSGrowHeaderViewController.m
More file actions
118 lines (84 loc) · 3.94 KB
/
CSGrowHeaderViewController.m
File metadata and controls
118 lines (84 loc) · 3.94 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
//
// CSGrowHeaderViewController.m
// CSStickyHeaderFlowLayoutDemo
//
// Created by James Tang on 13/2/14.
// Copyright (c) 2014 Jamz Tang. All rights reserved.
//
#import "CSGrowHeaderViewController.h"
#import "CSCell.h"
#import "CSSectionHeader.h"
#import "CSStickyHeaderFlowLayout.h"
@interface CSGrowHeaderViewController ()
@property (nonatomic, strong) NSArray *sections;
@property (nonatomic, strong) UINib *headerNib;
@end
@implementation CSGrowHeaderViewController
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.sections = @[
@{@"Twitter":@"http://twitter.com"},
@{@"Facebook":@"http://facebook.com"},
@{@"Tumblr":@"http://tumblr.com"},
@{@"Pinterest":@"http://pinterest.com"},
@{@"Instagram":@"http://instagram.com"},
@{@"Github":@"http://github.com"},
];
self.headerNib = [UINib nibWithNibName:@"CSGrowHeader" bundle:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self reloadLayout];
// Also insets the scroll indicator so it appears below the search bar
self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(44, 0, 0, 0);
[self.collectionView registerNib:self.headerNib
forSupplementaryViewOfKind:CSStickyHeaderParallaxHeader
withReuseIdentifier:@"header"];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self reloadLayout];
}
- (void)reloadLayout {
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
layout.parallaxHeaderReferenceSize = CGSizeMake(self.view.frame.size.width, 200);
layout.itemSize = CGSizeMake(self.view.frame.size.width, layout.itemSize.height);
// If we want to disable the sticky header effect
layout.disableStickyHeaders = YES;
}
}
#pragma mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return [self.sections count];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *obj = self.sections[indexPath.section];
CSCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell"
forIndexPath:indexPath];
cell.textLabel.text = [[obj allValues] firstObject];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
NSDictionary *obj = self.sections[indexPath.section];
CSSectionHeader *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"sectionHeader"
forIndexPath:indexPath];
cell.textLabel.text = [[obj allKeys] firstObject];
return cell;
} else if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {
UICollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:@"header"
forIndexPath:indexPath];
return cell;
}
return nil;
}
@end