Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support to scroll to a tile at a specific index path.

  • Loading branch information...
commit e4596857f82ea2474d234e0775c6028d7e5f842c 1 parent 149ac66
Cameron Hunt authored
2  CHGridLayout/CHGridLayout.h
View
@@ -60,6 +60,8 @@ static CHSectionRange CHSectionRangeMake(int start, int end){
- (CGFloat)yCoordinateForTitleOfSection:(int)section;
- (CHSectionRange)sectionRangeForContentOffset:(CGFloat)offset andHeight:(CGFloat)height;
+
+- (CHGridIndexPath)closestIndexPathToContentOffsetY:(CGFloat)offset;
- (CGRect)tileFrameForIndexPath:(CHGridIndexPath)indexPath;
- (CHGridIndexRange)rangeOfVisibleIndexesForContentOffset:(CGFloat)offset andHeight:(CGFloat)height;
22 CHGridLayout/CHGridLayout.m
View
@@ -180,6 +180,28 @@ - (CHSectionRange)sectionRangeForContentOffset:(CGFloat)offset andHeight:(CGFloa
return CHSectionRangeMake(start, end);
}
+- (CHGridIndexPath)closestIndexPathToContentOffsetY:(CGFloat)offset{
+ CHGridLayoutTile *closestTile = nil;
+
+ for(NSMutableArray *section in _index){
+ for(CHGridLayoutTile *tile in section){
+ if(tile.rect.origin.y > offset){
+ if(closestTile == nil){
+ closestTile = tile;
+ }else if(tile.rect.origin.y < closestTile.rect.origin.y && closestTile.rect.origin.y < offset){
+ closestTile = tile;
+ }
+ }
+ }
+ }
+
+ if(closestTile != nil){
+ NSLog(@"closest indexPath.section = %i tileIndex = %i", closestTile.indexPath.section, closestTile.indexPath.tileIndex);
+ return [closestTile indexPath];
+ }
+ return CHGridIndexPathMake(0, 0);
+}
+
- (CGRect)tileFrameForIndexPath:(CHGridIndexPath)indexPath{
NSMutableArray *sectionTiles = [_index objectAtIndex:indexPath.section];
return [[sectionTiles objectAtIndex:indexPath.tileIndex] rect];
2  CHGridView.h
View
@@ -86,6 +86,8 @@
- (CHTileView *)tileForIndexPath:(CHGridIndexPath)indexPath;
- (CHGridIndexPath)indexPathForPoint:(CGPoint)point;
+- (void)scrollToTileAtIndexPath:(CHGridIndexPath)indexPath animated:(BOOL)animated;
+
- (void)deselectTileAtIndexPath:(CHGridIndexPath)indexPath;
- (void)deselecSelectedTile;
11 CHGridView.m
View
@@ -25,7 +25,7 @@ - (void)calculateSectionTitleOffset;
@end
@implementation CHGridView
-@synthesize dynamicallyResizeTilesToFillSpace, allowsSelection, padding, rowHeight, perLine, sectionTitleHeight, shadowOffset, shadowColor, shadowBlur;
+@synthesize dynamicallyResizeTilesToFillSpace, allowsSelection, padding, preLoadMultiplier, rowHeight, perLine, sectionTitleHeight, shadowOffset, shadowColor, shadowBlur;
- (id)init{
return [self initWithFrame:CGRectZero];
@@ -274,7 +274,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){
CHSectionRange sectionRange = [layout sectionRangeForContentOffset:contentOffsetY andHeight:b.size.height];
@@ -345,6 +345,13 @@ - (CHGridIndexPath)indexPathForPoint:(CGPoint)point{
return CHGridIndexPathMake(0, 0);
}
+#pragma mark tile scrolling methods
+
+- (void)scrollToTileAtIndexPath:(CHGridIndexPath)indexPath animated:(BOOL)animated{
+ CGRect r = [layout tileFrameForIndexPath:indexPath];
+ [self scrollRectToVisible:r animated:animated];
+}
+
#pragma mark selection methods
- (void)deselectTileAtIndexPath:(CHGridIndexPath)indexPath{
2  README.markdown
View
@@ -24,8 +24,6 @@ NOTICE: **CHGridView is not production-level software yet. Don't use it in shipp
###Usage:
-[Download a sample view controller class](http://cameron.io/files/CHGridViewController.zip).
-
Exactly like UITableView. Just implement the two required data source methods: `numberOfTilesInSection` and `tileForIndexPath`. CHGridView assumes there is at least one section. The method `tileForIndexPath` works very much like UITableView; CHGridView reuses tiles just like UITableView reuses cells. Call `dequeueReusableTileWithIdentifier` to get a reusable tile, if it's `nil`, `init` and `autorelease` a new tile and return it.
There's two basic styles to use in GHGridView, one that resembles the Photos application, and one that mimics iPhoto and the iPad photo grid. The property that controls it is called `dynamicallyResizeTilesToFillSpace`. Set it to `YES` for the Photos app style.
Please sign in to comment.
Something went wrong with that request. Please try again.