forked from fdzsergio/SFFocusViewLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSFViewController.m
More file actions
93 lines (67 loc) · 2.71 KB
/
SFViewController.m
File metadata and controls
93 lines (67 loc) · 2.71 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
//
// SFViewController.m
// SFFocusViewLayout
//
// Created by Sergio Fernández on 10/05/2015.
// Copyright (c) 2015 Sergio Fernández. All rights reserved.
//
#import "SFViewController.h"
#import "SFCollectionViewCell.h"
#import "SFManager.h"
#import "SFPresenter.h"
#import "SFFocusViewLayout.h"
CGFloat const kSFFocusViewLayoutStandardHeight = 300;
static NSString * const kSFCollectionViewReuseIdentifier = @"__kSFCollectionViewReuseIdentifier";
@interface SFViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) SFManager *manager;
@end
@implementation SFViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast;
UINib *collectionViewcellNib = [UINib nibWithNibName:NSStringFromClass(SFCollectionViewCell.class)
bundle:nil];
[self.collectionView registerNib:collectionViewcellNib
forCellWithReuseIdentifier:kSFCollectionViewReuseIdentifier];
self.collectionView.backgroundColor = [UIColor colorWithRed:51/255.f green:55/255.f blue:61/255.f alpha:1.f];
self.manager = [SFManager new];
[self.manager loadResources];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
#pragma mark - UICollectionViewDataSource methods
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.resources.count;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
SFCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kSFCollectionViewReuseIdentifier
forIndexPath:indexPath];
return cell;
}
#pragma mark - UICollectionViewDelegate methods
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(SFCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
SFResource *resource = self.resources[indexPath.item];
[SFPresenter present:resource inView:cell];
}
#pragma mark - Private methods
- (NSArray *)resources
{
return self.manager.resources;
}
@end