Skip to content

Commit e2700b2

Browse files
committed
Work on UICollectionView instead of UITableView.
1 parent d0b25e8 commit e2700b2

File tree

6 files changed

+129
-19
lines changed

6 files changed

+129
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// MTZCollectionView.h
3+
// What's New
4+
//
5+
// Created by Matt Zanchelli on 5/23/14.
6+
// Copyright (c) 2014 Matt Zanchelli. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
/*
12+
A @c UICollectionView subclass that automatically enables and disables scrolling depending on whether or not the content fits within the scrollview's frame.
13+
*/
14+
@interface MTZCollectionView : UICollectionView
15+
16+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// MTZCollectionView.m
3+
// What's New
4+
//
5+
// Created by Matt Zanchelli on 5/23/14.
6+
// Copyright (c) 2014 Matt Zanchelli. All rights reserved.
7+
//
8+
9+
#import "MTZCollectionView.h"
10+
11+
@implementation MTZCollectionView
12+
13+
- (void)setContentSize:(CGSize)contentSize
14+
{
15+
[super setContentSize:contentSize];
16+
[self determineScrollingAbility];
17+
}
18+
19+
- (void)setFrame:(CGRect)frame
20+
{
21+
[super setFrame:frame];
22+
[self determineScrollingAbility];
23+
}
24+
25+
- (void)determineScrollingAbility
26+
{
27+
if (self.contentSize.height <= self.frame.size.height &&
28+
self.contentSize.width <= self.frame.size.width) {
29+
self.scrollEnabled = NO;
30+
} else {
31+
self.scrollEnabled = YES;
32+
}
33+
}
34+
35+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// MTZWhatsNewFeatureCollectionViewCell.h
3+
// What's New
4+
//
5+
// Created by Matt Zanchelli on 5/23/14.
6+
// Copyright (c) 2014 Matt Zanchelli. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface MTZWhatsNewFeatureCollectionViewCell : UICollectionViewCell
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// MTZWhatsNewFeatureCollectionViewCell.m
3+
// What's New
4+
//
5+
// Created by Matt Zanchelli on 5/23/14.
6+
// Copyright (c) 2014 Matt Zanchelli. All rights reserved.
7+
//
8+
9+
#import "MTZWhatsNewFeatureCollectionViewCell.h"
10+
11+
@implementation MTZWhatsNewFeatureCollectionViewCell
12+
13+
- (id)initWithFrame:(CGRect)frame
14+
{
15+
self = [super initWithFrame:frame];
16+
if (self) {
17+
// Initialization code
18+
}
19+
return self;
20+
}
21+
22+
/*
23+
// Only override drawRect: if you perform custom drawing.
24+
// An empty implementation adversely affects performance during animation.
25+
- (void)drawRect:(CGRect)rect
26+
{
27+
// Drawing code
28+
}
29+
*/
30+
31+
@end

Classes/MTZWhatsNewViewController/MTZWhatsNewViewController.m

+22-19
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88

99
#import "MTZWhatsNewViewController.h"
1010

11-
#import "MTZWhatsNewFeatureTableViewCell.h"
1211
#import "MTZTableView.h"
12+
#import "MTZWhatsNewFeatureTableViewCell.h"
13+
14+
#import "MTZCollectionView.h"
15+
#import "MTZWhatsNewFeatureCollectionViewCell.h"
16+
1317
#import "SAMGradientView.h"
1418

15-
@interface MTZWhatsNewViewController () <UITableViewDelegate, UITableViewDataSource>
19+
@interface MTZWhatsNewViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
1620

1721
/// An ordered list of the versions from newest to oldest.
1822
@property (strong, nonatomic) NSArray *orderedKeys;
1923

20-
/// The table view to display all the new features.
21-
@property (strong, nonatomic) MTZTableView *tableView;
24+
/// The collection view to display all the new features.
25+
@property (strong, nonatomic) MTZCollectionView *collectionView;
2226

2327
/// The gradient presented as the background.
2428
@property (strong, nonatomic) SAMGradientView *backgroundGradientView;
@@ -67,19 +71,18 @@ - (void)commonInit
6771
self.backgroundGradientView.gradientColors = @[[UIColor clearColor], [UIColor clearColor]];
6872
self.backgroundGradientView.gradientLocations = @[@0.0, @1.0];
6973

70-
// Feature table view.
71-
self.tableView = [[MTZTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
72-
self.tableView.delegate = self;
73-
self.tableView.dataSource = self;
74-
[self.tableView registerClass:[MTZWhatsNewFeatureTableViewCell class] forCellReuseIdentifier:@"feature"];
74+
// Feature collection view.
75+
self.collectionView = [[MTZCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:<#(UICollectionViewLayout *)#>];
76+
self.collectionView.delegate = self;
77+
self.collectionView.dataSource = self;
78+
[self.collectionView registerClass:[MTZWhatsNewFeatureCollectionViewCell class] forCellWithReuseIdentifier:@"feature"];
7579
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 0, 50, 0);
76-
self.tableView.scrollIndicatorInsets = edgeInsets;
77-
self.tableView.contentInset = edgeInsets;
78-
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
79-
self.tableView.backgroundColor = [UIColor clearColor];
80-
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
81-
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
82-
[self.view addSubview:self.tableView];
80+
self.collectionView.scrollIndicatorInsets = edgeInsets;
81+
self.collectionView.contentInset = edgeInsets;
82+
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
83+
self.collectionView.backgroundColor = [UIColor clearColor];
84+
self.collectionView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
85+
[self.view addSubview:self.collectionView];
8386

8487
// Get Started.
8588
CGRect frame = CGRectMake(0, self.view.bounds.size.height-50, self.view.bounds.size.width, 50);
@@ -99,7 +102,7 @@ - (void)commonInit
99102
- (void)viewDidAppear:(BOOL)animated
100103
{
101104
[super viewDidAppear:animated];
102-
[self.tableView flashScrollIndicators];
105+
[self.collectionView flashScrollIndicators];
103106
}
104107

105108
- (BOOL)prefersStatusBarHidden
@@ -125,8 +128,8 @@ - (void)setFeatures:(NSDictionary *)features
125128
return [obj2 compare:obj1 options:NSNumericSearch];
126129
}];
127130

128-
// Reload the table view's data.
129-
[self.tableView reloadData];
131+
// Reload the collection view's data.
132+
[self.collectionView reloadData];
130133
}
131134

132135
- (void)setTopColor:(UIColor *)topColor

Demo App/What's New.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
C95B8DBB192FB0D000D0A887 /* MTZWhatsNewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C95B8DB3192FB0D000D0A887 /* MTZWhatsNewViewController.m */; };
2828
C95B8DBC192FB0D000D0A887 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = C95B8DB5192FB0D000D0A887 /* LICENSE.txt */; };
2929
C95B8DBD192FB0D000D0A887 /* SAMGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = C95B8DB7192FB0D000D0A887 /* SAMGradientView.m */; };
30+
C9AC3B61192FBE2400797F24 /* MTZCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AC3B60192FBE2400797F24 /* MTZCollectionView.m */; };
31+
C9AC3B67192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AC3B66192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.m */; };
3032
/* End PBXBuildFile section */
3133

3234
/* Begin PBXContainerItemProxy section */
@@ -70,6 +72,10 @@
7072
C95B8DB5192FB0D000D0A887 /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
7173
C95B8DB6192FB0D000D0A887 /* SAMGradientView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAMGradientView.h; sourceTree = "<group>"; };
7274
C95B8DB7192FB0D000D0A887 /* SAMGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAMGradientView.m; sourceTree = "<group>"; };
75+
C9AC3B5F192FBE2400797F24 /* MTZCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTZCollectionView.h; sourceTree = "<group>"; };
76+
C9AC3B60192FBE2400797F24 /* MTZCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTZCollectionView.m; sourceTree = "<group>"; };
77+
C9AC3B65192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTZWhatsNewFeatureCollectionViewCell.h; sourceTree = "<group>"; };
78+
C9AC3B66192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTZWhatsNewFeatureCollectionViewCell.m; sourceTree = "<group>"; };
7379
/* End PBXFileReference section */
7480

7581
/* Begin PBXFrameworksBuildPhase section */
@@ -190,6 +196,10 @@
190196
C95B8DAF192FB0D000D0A887 /* MTZTableView.m */,
191197
C95B8DB0192FB0D000D0A887 /* MTZWhatsNewFeatureTableViewCell.h */,
192198
C95B8DB1192FB0D000D0A887 /* MTZWhatsNewFeatureTableViewCell.m */,
199+
C9AC3B5F192FBE2400797F24 /* MTZCollectionView.h */,
200+
C9AC3B60192FBE2400797F24 /* MTZCollectionView.m */,
201+
C9AC3B65192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.h */,
202+
C9AC3B66192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.m */,
193203
C95B8DB4192FB0D000D0A887 /* SAMGradientView */,
194204
);
195205
path = MTZWhatsNewViewController;
@@ -310,7 +320,9 @@
310320
C927692A1926C3240016A0F1 /* MTZAppDelegate.m in Sources */,
311321
C92769261926C3240016A0F1 /* main.m in Sources */,
312322
C92769331926C3240016A0F1 /* MTZViewController.m in Sources */,
323+
C9AC3B67192FBF9800797F24 /* MTZWhatsNewFeatureCollectionViewCell.m in Sources */,
313324
C95B8DBD192FB0D000D0A887 /* SAMGradientView.m in Sources */,
325+
C9AC3B61192FBE2400797F24 /* MTZCollectionView.m in Sources */,
314326
C95B8DB9192FB0D000D0A887 /* MTZTableView.m in Sources */,
315327
);
316328
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)