Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GMGridView/GMGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef enum
@property (nonatomic) BOOL disableEditOnEmptySpaceTap; // Default is NO

@property (nonatomic, readonly) UIScrollView *scrollView __attribute__((deprecated)); // The grid now inherits directly from UIScrollView
@property (nonatomic, strong) UIView *gridHeaderView; // Default is nil

// Reusable cells
- (GMGridViewCell *)dequeueReusableCell; // Should be called in GMGridView:cellForItemAtIndex: to reuse a cell
Expand Down
42 changes: 41 additions & 1 deletion GMGridView/GMGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ - (BOOL)isInTransformingState;
// Helpers & more
- (void)recomputeSizeAnimated:(BOOL)animated;
- (void)relayoutItemsAnimated:(BOOL)animated;
- (void)relayoutGridHeaderView:(BOOL)animated;
- (NSArray *)itemSubviews;
- (GMGridViewCell *)cellForItemAtIndex:(NSInteger)position;
- (GMGridViewCell *)newItemSubViewForPosition:(NSInteger)position;
Expand Down Expand Up @@ -147,6 +148,8 @@ @implementation GMGridView
@synthesize enableEditOnLongPress;
@synthesize disableEditOnEmptySpaceTap;

@synthesize gridHeaderView = _gridHeaderView;

@synthesize itemsSubviewsCacheIsValid = _itemsSubviewsCacheIsValid;
@synthesize itemSubviewsCache;

Expand Down Expand Up @@ -249,6 +252,7 @@ - (void)commonInit
self.showFullSizeViewWithAlphaWhenTransforming = YES;
self.minEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
self.clipsToBounds = NO;
self.gridHeaderView = nil;

_sortFuturePosition = GMGV_INVALID_POSITION;
_itemSize = CGSizeZero;
Expand Down Expand Up @@ -291,6 +295,7 @@ - (void)layoutSubviewsWithAnimation:(GMGridViewItemAnimation)animation
{
[self recomputeSizeAnimated:!(animation & GMGridViewItemAnimationNone)];
[self relayoutItemsAnimated:animation & GMGridViewItemAnimationFade]; // only supported animation for now
[self relayoutGridHeaderView:!(animation & GMGridViewItemAnimationNone)];
[self loadRequiredItems];
}

Expand Down Expand Up @@ -456,6 +461,17 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated
}
}

- (void)setGridHeaderView:(UIView *)gridHeaderView
{
if (_gridHeaderView == gridHeaderView) return;

if (_gridHeaderView) [_gridHeaderView removeFromSuperview];
_gridHeaderView = gridHeaderView;
if (_gridHeaderView) [self.scrollView addSubview:_gridHeaderView];

[self setNeedsLayout];
}

//////////////////////////////////////////////////////////////
#pragma mark UIScrollView delegate replacement
//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1265,7 +1281,12 @@ - (NSInteger)positionForItemSubview:(GMGridViewCell *)view

- (void)recomputeSizeAnimated:(BOOL)animated
{
[self.layoutStrategy setupItemSize:_itemSize andItemSpacing:self.itemSpacing withMinEdgeInsets:self.minEdgeInsets andCenteredGrid:self.centerGrid];
UIEdgeInsets minEdgeInsets = self.minEdgeInsets;
if (self.gridHeaderView) {
minEdgeInsets.top += self.gridHeaderView.bounds.size.height;
}

[self.layoutStrategy setupItemSize:_itemSize andItemSpacing:self.itemSpacing withMinEdgeInsets:minEdgeInsets andCenteredGrid:self.centerGrid];
[self.layoutStrategy rebaseWithItemCount:_numberTotalItems insideOfBounds:self.bounds];

CGSize contentSize = [self.layoutStrategy contentSize];
Expand Down Expand Up @@ -1766,6 +1787,25 @@ - (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2
}];
}

- (void)relayoutGridHeaderView:(BOOL)animated;
{
CGRect frame = CGRectMake(0, 0, self.bounds.size.width, self.gridHeaderView.bounds.size.height);
if (animated)
{
[UIView animateWithDuration:kDefaultAnimationDuration
delay:0
options:kDefaultAnimationOptions
animations:^{
self.gridHeaderView.frame = frame;
}
completion:nil
];
}
else
{
self.gridHeaderView.frame = frame;
}
}

//////////////////////////////////////////////////////////////
#pragma mark depracated public methods
Expand Down
10 changes: 5 additions & 5 deletions GMGridView/GMGridView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
16A0361514A012EF0062437D /* UIView+GMGridViewAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 16A0361314A012EF0062437D /* UIView+GMGridViewAdditions.h */; };
16A0361614A012EF0062437D /* UIView+GMGridViewAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 16A0361414A012EF0062437D /* UIView+GMGridViewAdditions.m */; };
78509316149FAC2E000787E4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78509315149FAC2E000787E4 /* Foundation.framework */; };
78509341149FAC61000787E4 /* GMGridView-Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509335149FAC61000787E4 /* GMGridView-Constants.h */; settings = {ATTRIBUTES = (Public, ); }; };
78509342149FAC61000787E4 /* GMGridView.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509336149FAC61000787E4 /* GMGridView.h */; settings = {ATTRIBUTES = (Public, ); }; };
78509341149FAC61000787E4 /* GMGridView-Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509335149FAC61000787E4 /* GMGridView-Constants.h */; settings = {ATTRIBUTES = (); }; };
78509342149FAC61000787E4 /* GMGridView.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509336149FAC61000787E4 /* GMGridView.h */; settings = {ATTRIBUTES = (); }; };
78509343149FAC61000787E4 /* GMGridView.m in Sources */ = {isa = PBXBuildFile; fileRef = 78509337149FAC61000787E4 /* GMGridView.m */; };
78509344149FAC61000787E4 /* GMGridViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509338149FAC61000787E4 /* GMGridViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
78509344149FAC61000787E4 /* GMGridViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 78509338149FAC61000787E4 /* GMGridViewCell.h */; settings = {ATTRIBUTES = (); }; };
78509345149FAC61000787E4 /* GMGridViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 78509339149FAC61000787E4 /* GMGridViewCell.m */; };
78509346149FAC61000787E4 /* GMGridViewCell+Extended.h in Headers */ = {isa = PBXBuildFile; fileRef = 7850933A149FAC61000787E4 /* GMGridViewCell+Extended.h */; settings = {ATTRIBUTES = (Public, ); }; };
78509347149FAC61000787E4 /* GMGridViewLayoutStrategies.h in Headers */ = {isa = PBXBuildFile; fileRef = 7850933B149FAC61000787E4 /* GMGridViewLayoutStrategies.h */; settings = {ATTRIBUTES = (Public, ); }; };
78509346149FAC61000787E4 /* GMGridViewCell+Extended.h in Headers */ = {isa = PBXBuildFile; fileRef = 7850933A149FAC61000787E4 /* GMGridViewCell+Extended.h */; settings = {ATTRIBUTES = (); }; };
78509347149FAC61000787E4 /* GMGridViewLayoutStrategies.h in Headers */ = {isa = PBXBuildFile; fileRef = 7850933B149FAC61000787E4 /* GMGridViewLayoutStrategies.h */; settings = {ATTRIBUTES = (); }; };
78509348149FAC61000787E4 /* GMGridViewLayoutStrategies.m in Sources */ = {isa = PBXBuildFile; fileRef = 7850933C149FAC61000787E4 /* GMGridViewLayoutStrategies.m */; };
78509350149FAC71000787E4 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7850934D149FAC71000787E4 /* QuartzCore.framework */; };
78509351149FAC71000787E4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7850934E149FAC71000787E4 /* UIKit.framework */; };
Expand Down
2 changes: 1 addition & 1 deletion GMGridView/GMGridViewLayoutStrategies.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (NSRange)rangeOfPositionsInBoundsFromOffset:(CGPoint)offset

CGFloat itemHeight = self.itemSize.height + self.itemSpacing;

CGFloat firstRow = MAX(0, (int)(contentOffset.y / itemHeight) - 1);
CGFloat firstRow = MAX(0, (int)((contentOffset.y-self.edgeInsets.top) / itemHeight) - 1);

CGFloat lastRow = ceil((contentOffset.y + self.gridBounds.size.height) / itemHeight);

Expand Down