Permalink
Browse files

Couple fixes, README change

  • Loading branch information...
1 parent b63d60a commit 2e80c43c5b2d647229fe39e7caf8d7955a638eff @camh committed Feb 23, 2010
Showing with 20 additions and 24 deletions.
  1. +7 −10 CHGridLayout/CHGridLayout.m
  2. +11 −12 CHGridView.m
  3. +1 −1 CHTileView.m
  4. +1 −1 README.markdown
@@ -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;
@@ -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;
}
View
@@ -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)];
@@ -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;
@@ -193,8 +193,6 @@ - (void)reuseHiddenTiles{
for(CHTileView *tile in toReuse){
[self reuseTile:tile];
}
-
- [toReuse release];
}
- (void)reuseTile:(CHTileView *)tile{
@@ -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){
@@ -217,8 +215,6 @@ - (void)removeSectionTitleNotInRange:(CHSectionRange)range{
[title removeFromSuperview];
[visibleSectionTitles removeObject:title];
}
-
- [toDelete release];
}
- (void)reloadData{
@@ -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];
@@ -247,7 +247,6 @@ - (void)reloadData{
}
[layout updateLayout];
-
[self setNeedsLayout];
}
@@ -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;
View
@@ -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]){
View
@@ -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.