Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A couple performance enhancements

  • Loading branch information...
commit 1d1d2cb6ad402e0f2fc12ea0a02bcbd69882da6c 1 parent a0a5086
@camh authored
View
9 CHGridLayout/CHGridLayout.h
@@ -33,12 +33,13 @@ static CHSectionRange CHSectionRangeMake(int start, int end){
NSMutableArray *_index;
NSMutableArray *_sectionTitles;
- CGFloat gridWidth;
- CGFloat contentHeight;
+ float gridWidth;
+ float contentHeight;
CGSize padding;
int perLine;
- CGFloat rowHeight;
- CGFloat sectionTitleHeight;
+ float rowHeight;
+ float pixelMargin;
+ float sectionTitleHeight;
BOOL dynamicallyResizeTilesToFillSpace;
}
View
17 CHGridLayout/CHGridLayout.m
@@ -37,6 +37,11 @@ - (void)dealloc{
#pragma mark setters
+- (void)setRowHeight:(CGFloat)f{
+ rowHeight = f;
+ pixelMargin = f * 2;
+}
+
- (void)setSections:(int)sections{
[self clearData];
@@ -123,13 +128,12 @@ - (void)updateLayout{
- (int)sectionIndexForContentOffset:(CGFloat)offset{
int sectionIndex = 0;
- int i;
- for(i = 0; i < _sectionTitles.count; i++){
- CHGridLayoutSection *section = [_sectionTitles objectAtIndex:i];
+ for(CHGridLayoutSection *section in _sectionTitles){
if(section.yCoordinate <= offset && offset > 0){
- sectionIndex = i;
+ sectionIndex = section.section;
}
}
+
return sectionIndex;
}
@@ -142,7 +146,6 @@ - (CHSectionRange)sectionRangeForContentOffset:(CGFloat)offset andHeight:(CGFloa
int end = 0;
BOOL firstRun = YES;
- float pixelMargin = rowHeight * 2;
int currentSection = [self sectionIndexForContentOffset:offset];
for(CHGridLayoutSection *section in _sectionTitles){
@@ -168,9 +171,7 @@ - (CGRect)tileFrameForIndexPath:(CHGridIndexPath)indexPath{
}
- (CHGridIndexRange)rangeOfVisibleIndexesForContentOffset:(CGFloat)offset andHeight:(CGFloat)height{
- float pixelMargin = rowHeight * 2;
BOOL first = NO;
-
CHGridIndexRange indexRange = {CHGridIndexPathMake(0, 0),CHGridIndexPathMake(0, 0)};
for(NSMutableArray *sectionArray in _index){
@@ -185,8 +186,6 @@ - (CHGridIndexRange)rangeOfVisibleIndexesForContentOffset:(CGFloat)offset andHei
}
}
- first = NO;
-
return indexRange;
}
View
28 CHGridView.m
@@ -16,7 +16,6 @@ - (void)loadVisibleSectionTitlesForSectionRange:(CHSectionRange)range;
- (void)loadVisibleTilesForIndexPathRange:(CHGridIndexRange)range;
- (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath;
- (void)reuseHiddenTiles;
-- (void)reuseTile:(CHTileView *)tile;
- (void)removeSectionTitleNotInRange:(CHSectionRange)range;
- (void)removeAllSubviews;
- (NSMutableArray *)tilesForSection:(int)section;
@@ -178,32 +177,28 @@ - (void)loadVisibleTileForIndexPath:(CHGridIndexPath)indexPath{
}
- (void)reuseHiddenTiles{
- NSMutableArray *toReuse = [NSMutableArray array];
+ NSMutableArray *toReuse = [[NSMutableArray alloc] init];
CGRect b = self.bounds;
CGFloat contentOffsetY = self.contentOffset.y;
float pixelMargin = rowHeight * 2;
+ int maxReusable = [self maxNumberOfReusableTiles];
for(CHTileView *tile in visibleTiles){
if(tile.frame.origin.y + tile.frame.size.height < (contentOffsetY - pixelMargin) || tile.frame.origin.y > (contentOffsetY + b.size.height + pixelMargin)){
[toReuse addObject:tile];
+ if(reusableTiles.count < maxReusable) [reusableTiles addObject:tile];
}
}
- for(CHTileView *tile in toReuse){
- [self reuseTile:tile];
- }
-}
-
-- (void)reuseTile:(CHTileView *)tile{
- if(reusableTiles.count < [self maxNumberOfReusableTiles]) [reusableTiles addObject:tile];
+ [toReuse makeObjectsPerformSelector:@selector(removeFromSuperview)];
+ [visibleTiles removeObjectsInArray:toReuse];
- [tile removeFromSuperview];
- [visibleTiles removeObject:tile];
+ [toReuse release];
}
- (void)removeSectionTitleNotInRange:(CHSectionRange)range{
- NSMutableArray *toDelete = [NSMutableArray array];
+ NSMutableArray *toDelete = [[NSMutableArray alloc] init];
for (CHSectionTitleView *title in visibleSectionTitles) {
if(title.section < range.start || title.section > range.end){
@@ -211,10 +206,9 @@ - (void)removeSectionTitleNotInRange:(CHSectionRange)range{
}
}
- for(CHSectionTitleView *title in toDelete){
- [title removeFromSuperview];
- [visibleSectionTitles removeObject:title];
- }
+ [toDelete makeObjectsPerformSelector:@selector(removeFromSuperview)];
+ [visibleSectionTitles removeObjectsInArray:toDelete];
+ [toDelete release];
}
- (void)reloadData{
@@ -439,8 +433,6 @@ - (void)calculateSectionTitleOffset{
if((offset + sectionTwo.frame.size.height) >= sectionTwo.yCoordinate){
f.origin.y = sectionTwo.yCoordinate - sectionTwo.frame.size.height;
}
-
- //[self bringSubviewToFront:sectionTwo];
}
}else{
f.origin.y = title.yCoordinate;
View
2  README.markdown
@@ -47,7 +47,7 @@ If you disable scrolling with `setScrollingEnabled`, you can probably use this a
###Roadmap (roughly in order):
-- Match speed and performance found in iPhone's Photos app grid view
+- Match or exceed speed and performance found in iPhone's Photos app grid view
- More UITableView cloning, like scrolling to a tile at a specific indexPath
- Tile labels
- Flexible per-line setting (maybe a range?)
Please sign in to comment.
Something went wrong with that request. Please try again.