diff --git a/GMGridView/GMGridView.h b/GMGridView/GMGridView.h index 7282e1d..cfa0451 100644 --- a/GMGridView/GMGridView.h +++ b/GMGridView/GMGridView.h @@ -107,6 +107,7 @@ typedef enum - (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 animated:(BOOL)animated; - (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 withAnimation:(GMGridViewItemAnimation)animation; - (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrollPosition)scrollPosition animated:(BOOL)animated; +- (void)scrollToPageIndex:(NSInteger)index animated:(BOOL)animated; // Force the grid to update properties in an (probably) animated way. - (void)layoutSubviewsWithAnimation:(GMGridViewItemAnimation)animation; diff --git a/GMGridView/GMGridView.m b/GMGridView/GMGridView.m index c362c29..3a1f4bc 100644 --- a/GMGridView/GMGridView.m +++ b/GMGridView/GMGridView.m @@ -476,9 +476,22 @@ - (void)contentOffset:(CGPoint)contentOffset ////////////////////////////////////////////////////////////// #pragma mark GestureRecognizer delegate ////////////////////////////////////////////////////////////// +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch +{ + if ( gestureRecognizer == _tapGesture) { + if ( [touch.view isDescendantOfView:self] ) { + // Test if the touched view is a subview of a control + for ( UIView *view = touch.view ; view != self ; view = view.superview ) + if ( [view isKindOfClass:[UIControl class]] ) + return NO; + } + } + + return YES; +} - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer -{ +{ return YES; } @@ -1611,6 +1624,25 @@ - (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrol ]; } +- (void)scrollToPageIndex:(NSInteger)index animated:(BOOL)animated +{ + int pages = [self.layoutStrategy numberOfPages]; + if(index >= 0 && index < pages) + { + int scrollToX = self.frame.size.width * index; + [UIView animateWithDuration:animated ? kDefaultAnimationDuration : 0 + delay:0 + options:kDefaultAnimationOptions + animations:^{ + [self setContentOffset:CGPointMake(scrollToX, 0) animated:NO]; + } + completion:^(BOOL finished){ + } + ]; + + } +} + - (void)insertObjectAtIndex:(NSInteger)index animated:(BOOL)animated { [self insertObjectAtIndex:index withAnimation: animated ? GMGridViewItemAnimationScroll : GMGridViewItemAnimationNone]; diff --git a/GMGridView/GMGridView.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/GMGridView/GMGridView.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..93d3e8a --- /dev/null +++ b/GMGridView/GMGridView.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/GMGridView/GMGridViewLayoutStrategies.h b/GMGridView/GMGridViewLayoutStrategies.h index 5b816b0..b253d14 100644 --- a/GMGridView/GMGridViewLayoutStrategies.h +++ b/GMGridView/GMGridViewLayoutStrategies.h @@ -76,6 +76,9 @@ typedef enum { - (NSRange)rangeOfPositionsInBoundsFromOffset:(CGPoint)offset; +@optional +- (NSInteger)numberOfPages; + @end diff --git a/GMGridView/GMGridViewLayoutStrategies.m b/GMGridView/GMGridViewLayoutStrategies.m index 71919ad..1cfe46a 100644 --- a/GMGridView/GMGridViewLayoutStrategies.m +++ b/GMGridView/GMGridViewLayoutStrategies.m @@ -511,6 +511,11 @@ - (NSRange)rangeOfPositionsInBoundsFromOffset:(CGPoint)offset return NSMakeRange(firstPosition, (lastPosition - firstPosition)); } +- (NSInteger)numberOfPages +{ + return _numberOfPages; +} + @end