Skip to content

Commit

Permalink
Couple fixes, README change
Browse files Browse the repository at this point in the history
  • Loading branch information
camh committed Feb 23, 2010
1 parent b63d60a commit 2e80c43
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
17 changes: 7 additions & 10 deletions CHGridLayout/CHGridLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ - (void)updateLayout{

float perLineFloat = perLine;

int u;
for(u = 0; u < _index.count; u++){
int numberOfTilesInSection = [[_index objectAtIndex:u] count];
for(NSMutableArray *array in _index){
int numberOfTilesInSection = [array count];
contentHeight += ceil(numberOfTilesInSection / perLineFloat) * rowHeight;
}

if(sections > 1) contentHeight += (sectionTitleHeight * sections) + ((sections - 1) * padding.height);
contentHeight += padding.height;

Expand Down Expand Up @@ -145,19 +145,16 @@ - (CHSectionRange)sectionRangeForContentOffset:(CGFloat)offset andHeight:(CGFloa
float pixelMargin = rowHeight * 2;
int currentSection = [self sectionIndexForContentOffset:offset];

int i;
for(i = currentSection; i < _sectionTitles.count; i++){
if(firstRun){
start = i;
for(CHGridLayoutSection *section in _sectionTitles){
if(firstRun && section.section >= currentSection){
start = section.section;
firstRun = NO;
}

CHGridLayoutSection *section = [_sectionTitles objectAtIndex:i];

if(section.yCoordinate > (offset - pixelMargin) && section.yCoordinate < (offset + height + pixelMargin)){
end = section.section;
}

if(start > end) end = start;
}

Expand Down
23 changes: 11 additions & 12 deletions CHGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
centeredRect.origin.y += rect.origin.y;
centeredRect.origin.x += rect.origin.x;
[tile setFrame:centeredRect];
[tile setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin )];
[tile setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin)];
}else{
[tile setFrame:rect];
[tile setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth)];
Expand All @@ -178,7 +178,7 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
}

- (void)reuseHiddenTiles{
NSMutableArray *toReuse = [[NSMutableArray alloc] init];
NSMutableArray *toReuse = [NSMutableArray array];

CGRect b = self.bounds;
CGFloat contentOffsetY = self.contentOffset.y;
Expand All @@ -193,8 +193,6 @@ - (void)reuseHiddenTiles{
for(CHTileView *tile in toReuse){
[self reuseTile:tile];
}

[toReuse release];
}

- (void)reuseTile:(CHTileView *)tile{
Expand All @@ -205,7 +203,7 @@ - (void)reuseTile:(CHTileView *)tile{
}

- (void)removeSectionTitleNotInRange:(CHSectionRange)range{
NSMutableArray *toDelete = [[NSMutableArray alloc] init];
NSMutableArray *toDelete = [NSMutableArray array];

for (CHSectionTitleView *title in visibleSectionTitles) {
if(title.section < range.start || title.section > range.end){
Expand All @@ -217,8 +215,6 @@ - (void)removeSectionTitleNotInRange:(CHSectionRange)range{
[title removeFromSuperview];
[visibleSectionTitles removeObject:title];
}

[toDelete release];
}

- (void)reloadData{
Expand All @@ -230,9 +226,13 @@ - (void)reloadData{

CGRect b = [self bounds];

if([dataSource respondsToSelector:@selector(numberOfSectionsInGridView:)])sections = [dataSource numberOfSectionsInGridView:self];
else sections = 1;

if([dataSource respondsToSelector:@selector(numberOfSectionsInGridView:)]){
sections = [dataSource numberOfSectionsInGridView:self];
if(sections == 0) sections = 1;
}else {
sections = 1;
}

[layout setGridWidth:b.size.width];
[layout setPadding:padding];
[layout setPerLine:perLine];
Expand All @@ -247,7 +247,6 @@ - (void)reloadData{
}

[layout updateLayout];

[self setNeedsLayout];
}

Expand All @@ -273,7 +272,7 @@ - (void)layoutSubviews{
CHGridIndexRange tileRange = [layout rangeOfVisibleIndexesForContentOffset:contentOffsetY andHeight:b.size.height];
[self loadVisibleTilesForIndexPathRange:tileRange];

//if([gridDelegate respondsToSelector:@selector(visibleTilesChangedTo:)]) [gridDelegate visibleTilesChangedTo:visibleTiles.count];
if([gridDelegate respondsToSelector:@selector(visibleTilesChangedTo:)]) [gridDelegate visibleTilesChangedTo:visibleTiles.count];

if(sections <= 1) return;

Expand Down
2 changes: 1 addition & 1 deletion CHTileView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "CHTileView.h"

@implementation CHTileView
@synthesize indexPath, selected, highlighted, reuseIdentifier, shadowOffset, shadowColor, shadowBlur;
@synthesize indexPath, selected, highlighted, contentBackgroundColor, reuseIdentifier, shadowOffset, shadowColor, shadowBlur;

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseId{
if(self = [super initWithFrame:frame]){
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a

I've tested CHGridView informally with a test application on both my iPhones. For my data source, I used 31 images to populate 1,984 tiles separated with 64 sections. They were exported from iPhoto as PNGs with a maximum width of 160 pixels. The images were drawn centered in CHImageTileView. Scrolling performance is not as good as Apple's Photos grid view, especially on my original iPhone.

- Original iPhone: average 10 - 25 fps.
- Original iPhone: about 12 - 30 fps.
- iPhone 3G3: average 30 - 50 fps.

Admittedly, performance could be better. I'm not an incredibly experienced programmer, so I'm not privy to a lot of formal programming knowledge. If you see something that could be better, send an email to [me@cameron.io](mailto:me@cameron.io).

0 comments on commit 2e80c43

Please sign in to comment.