Skip to content
Browse files

Improved reusable cells converter and changed README

  • Loading branch information...
1 parent e25740d commit 61e3b0e598e44abd4ca44d137a72a7761199199c @camh committed Feb 22, 2010
Showing with 11 additions and 8 deletions.
  1. +9 −6 CHGridView.m
  2. +2 −2 README.markdown
View
15 CHGridView.m
@@ -15,7 +15,7 @@ - (int)maxNumberOfReusableTiles;
- (void)loadVisibleSectionTitlesForSectionRange:(CHSectionRange)range;
- (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range;
- (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath;
-- (void)reuseTilesOutsideOfIndexPathRange:(CHGridIndexRange)range;
+- (void)reuseHiddenTiles;
- (void)reuseTile:(CHTileView *)tile;
- (void)removeSectionTitleNotInRange:(CHSectionRange)range;
- (void)removeAllSubviews;
@@ -140,7 +140,7 @@ - (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range{
}
}
- [self reuseTilesOutsideOfIndexPathRange:range];
+ [self reuseHiddenTiles];
}
- (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
@@ -177,12 +177,15 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
[visibleTiles addObject:tile];
}
-- (void)reuseTilesOutsideOfIndexPathRange:(CHGridIndexRange)range{
+- (void)reuseHiddenTiles{
NSMutableArray *toReuse = [[NSMutableArray alloc] init];
+ CGRect b = self.bounds;
+ CGFloat contentOffsetY = self.contentOffset.y;
+ float pixelMargin = rowHeight * 2;
+
for(CHTileView *tile in visibleTiles){
- if((tile.indexPath.section <= range.start.section && tile.indexPath.tileIndex < range.start.tileIndex) ||
- (tile.indexPath.section >= range.end.section && tile.indexPath.tileIndex > range.end.tileIndex)){
+ if(tile.frame.origin.y + tile.frame.size.height < (contentOffsetY - pixelMargin) || tile.frame.origin.y > (contentOffsetY + b.size.height + pixelMargin)){
[toReuse addObject:tile];
}
}
@@ -270,7 +273,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
4 README.markdown
@@ -38,7 +38,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a
###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.
- 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.
@@ -56,7 +56,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a
###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.
- iPhone 3G3: average 30 - 50 fps.

0 comments on commit 61e3b0e

Please sign in to comment.
Something went wrong with that request. Please try again.