Skip to content

Commit

Permalink
Improved SSCollectionView drawing and added header/footer height control
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Sep 2, 2010
1 parent 9947d6f commit 87508c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions SSToolkit.xcodeproj/project.pbxproj
Expand Up @@ -452,7 +452,14 @@
};
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "SSToolkit" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 0867D691FE84028FC02AAC07 /* TWToolkit */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
Expand Down
13 changes: 11 additions & 2 deletions SSToolkit/SSCollectionView.h
Expand Up @@ -15,6 +15,9 @@
// Editing will and performance will be my next focus. Then animating
// changes when data changes and an option to disable that.
//
// Don't mind all of the comments in the header. They are mainly for future
// features. You could be awesome and implement a few :)
//

#import "SSCollectionViewItem.h"

Expand Down Expand Up @@ -158,15 +161,21 @@

@optional

// Headers and Footers
- (CGFloat)collectionView:(SSCollectionView *)aCollectionView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)collectionView:(SSCollectionView *)aCollectionView heightForFooterInSection:(NSInteger)section;
//- (UIView *)collectionView:(SSCollectionView *)aCollectionView viewForHeaderInSection:(NSInteger)section;
//- (UIView *)collectionView:(SSCollectionView *)aCollectionView viewForFooterInSection:(NSInteger)section;
//- (BOOL)collectionView:(SSCollectionView *)aCollectionView headerForSectionIsSticky:(NSInteger)section;
//- (BOOL)collectionView:(SSCollectionView *)aCollectionView footerForSectionIsSticky:(NSInteger)section;

- (void)collectionView:(SSCollectionView *)aCollectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;

//- (void)collectionView:(SSCollectionView *)aCollectionView willDisplayItem:(SSCollectionViewItem *)item forIndexPath:(NSIndexPath *)indexPath;
//
//- (UITableViewItemEditingStyle)tableView:(UITableView *)tableView editingStyleForItemAtIndexPath:(NSIndexPath *)indexPath;
//- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForItemAtIndexPath:(NSIndexPath *)indexPath;
//- (void)tableView:(UITableView*)tableView willBeginEditingItemAtIndexPath:(NSIndexPath *)indexPath;
//- (void)tableView:(UITableView*)tableView didEndEditingItemAtIndexPath:(NSIndexPath *)indexPath;
//
//- (NSUInteger)aCollectionView:(SSCollectionView *)aCollectionView targetIndexPathForMoveFromItemAtIndexPath:(NSIndexPath *)indexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;

@end
17 changes: 15 additions & 2 deletions SSToolkit/SSCollectionView.m
Expand Up @@ -89,6 +89,18 @@ - (void)layoutSubviews {
// Calculate padding
CGFloat horizontalPadding = roundf((totalWidth - (_columnWidth * maxColumns) - (_columnSpacing * (maxColumns - 1))) / 2.0);

// Calculate verticalOffset
CGFloat verticalOffset = 0.0;
if ([self.delegate respondsToSelector:@selector(collectionView:heightForHeaderInSection:)]) {
verticalOffset = [self.delegate collectionView:self heightForHeaderInSection:0];
}

// Calculate bottomPadding
CGFloat bottomPadding = 0.0;
if ([self.delegate respondsToSelector:@selector(collectionView:heightForFooterInSection:)]) {
bottomPadding = [self.delegate collectionView:self heightForFooterInSection:0];
}

// Layout items
NSUInteger index = 0;
NSUInteger row = 0;
Expand All @@ -99,14 +111,14 @@ - (void)layoutSubviews {
column = 0;
row++;
}
item.frame = CGRectMake((column * _columnWidth) + (column * _columnSpacing) + horizontalPadding, (row * _rowHeight) + (row * _rowSpacing), _columnWidth, _rowHeight);
item.frame = CGRectMake((column * _columnWidth) + (column * _columnSpacing) + horizontalPadding, (row * _rowHeight) + (row * _rowSpacing) + verticalOffset, _columnWidth, _rowHeight);
index++;
}

// Set content size
CGRect lastFrame = [[_items lastObject] frame];
CGFloat contentWidth = totalWidth - self.contentInset.left - self.contentInset.right;
CGFloat contentHeight = lastFrame.origin.y + lastFrame.size.height + _rowSpacing;
CGFloat contentHeight = lastFrame.origin.y + lastFrame.size.height + bottomPadding;
CGFloat minContentHeight = (self.frame.size.height - self.contentInset.top - self.contentInset.bottom) + 1.0;
self.contentSize = CGSizeMake(contentWidth, fmax(contentHeight, minContentHeight));

Expand Down Expand Up @@ -157,6 +169,7 @@ - (void)reloadData {
// TODO: This is wildly inefficient. Only grab items
// that will be on the screen

[_items makeObjectsPerformSelector:@selector(removeFromSuperview)];
[_items removeAllObjects];

NSUInteger total = [_dataSource collectionView:self numberOfRowsInSection:0];
Expand Down
6 changes: 6 additions & 0 deletions SSToolkit/SSCollectionViewController.m
Expand Up @@ -37,6 +37,12 @@ - (void)loadView {
}


- (void)viewDidLoad {
[super viewDidLoad];
[_collectionView reloadData];
}


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_collectionView flashScrollIndicators];
Expand Down

0 comments on commit 87508c8

Please sign in to comment.