Skip to content

Commit

Permalink
Improved reusable cells converter and changed README
Browse files Browse the repository at this point in the history
  • Loading branch information
camh committed Feb 22, 2010
1 parent e25740d commit 61e3b0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions CHGridView.m
Expand Up @@ -15,7 +15,7 @@ - (int)maxNumberOfReusableTiles;
- (void)loadVisibleSectionTitlesForSectionRange:(CHSectionRange)range; - (void)loadVisibleSectionTitlesForSectionRange:(CHSectionRange)range;
- (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range; - (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range;
- (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath; - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath;
- (void)reuseTilesOutsideOfIndexPathRange:(CHGridIndexRange)range; - (void)reuseHiddenTiles;
- (void)reuseTile:(CHTileView *)tile; - (void)reuseTile:(CHTileView *)tile;
- (void)removeSectionTitleNotInRange:(CHSectionRange)range; - (void)removeSectionTitleNotInRange:(CHSectionRange)range;
- (void)removeAllSubviews; - (void)removeAllSubviews;
Expand Down Expand Up @@ -140,7 +140,7 @@ - (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range{
} }
} }


[self reuseTilesOutsideOfIndexPathRange:range]; [self reuseHiddenTiles];
} }


- (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
Expand Down Expand Up @@ -177,12 +177,15 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
[visibleTiles addObject:tile]; [visibleTiles addObject:tile];
} }


- (void)reuseTilesOutsideOfIndexPathRange:(CHGridIndexRange)range{ - (void)reuseHiddenTiles{
NSMutableArray *toReuse = [[NSMutableArray alloc] init]; NSMutableArray *toReuse = [[NSMutableArray alloc] init];


CGRect b = self.bounds;
CGFloat contentOffsetY = self.contentOffset.y;
float pixelMargin = rowHeight * 2;

for(CHTileView *tile in visibleTiles){ for(CHTileView *tile in visibleTiles){
if((tile.indexPath.section <= range.start.section && tile.indexPath.tileIndex < range.start.tileIndex) || if(tile.frame.origin.y + tile.frame.size.height < (contentOffsetY - pixelMargin) || tile.frame.origin.y > (contentOffsetY + b.size.height + pixelMargin)){
(tile.indexPath.section >= range.end.section && tile.indexPath.tileIndex > range.end.tileIndex)){
[toReuse addObject:tile]; [toReuse addObject:tile];
} }
} }
Expand Down Expand Up @@ -270,7 +273,7 @@ - (void)layoutSubviews{
CHGridIndexRange tileRange = [layout rangeOfVisibleIndexesForContentOffset:contentOffsetY andHeight:b.size.height]; CHGridIndexRange tileRange = [layout rangeOfVisibleIndexesForContentOffset:contentOffsetY andHeight:b.size.height];
[self loadVisibleTilesForIndexPathRange:tileRange]; [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; if(sections <= 1) return;


Expand Down
4 changes: 2 additions & 2 deletions README.markdown
Expand Up @@ -38,7 +38,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a


###Behind the scenes: ###Behind the scenes:


- CHGridView only loads visible tiles and section titles, plus two rows above and beneath. On the iPhone there's only about 30 to 60 tiles loaded at a time. - CHGridView only loads visible tiles and section titles, plus two rows above and beneath. On the iPhone there's only about 30 tiles loaded at a time.
- CHTileView shadows are not transparent, they are rendered onto the same background color as CHGridView. It's possible to change it if you long for the scrolling performance of Android or WebOS. - CHTileView shadows are not transparent, they are rendered onto the same background color as CHGridView. It's possible to change it if you long for the scrolling performance of Android or WebOS.
- CHImageTileView supports scaling images up/down to fit its frame (and preserves aspect ratio) but it's not fast enough to use. The property is called `scalesImageToHeight` and you should never use it. - CHImageTileView supports scaling images up/down to fit its frame (and preserves aspect ratio) but it's not fast enough to use. The property is called `scalesImageToHeight` and you should never use it.
- Section titles are only transparent when they need to be, otherwise they are opaque. If you subclass CHSectionTitleView, you'll need to check [self isOpaque] to deal with transparency on your own. - Section titles are only transparent when they need to be, otherwise they are opaque. If you subclass CHSectionTitleView, you'll need to check [self isOpaque] to deal with transparency on your own.
Expand All @@ -56,7 +56,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a


###Performance: ###Performance:


I 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. 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: average 10 - 25 fps.
- iPhone 3G3: average 30 - 50 fps. - iPhone 3G3: average 30 - 50 fps.
Expand Down

0 comments on commit 61e3b0e

Please sign in to comment.