Skip to content

Commit

Permalink
Merge pull request #48 from smartmobilefactory/simultaneouslyGestureR…
Browse files Browse the repository at this point in the history
…ecognizerChoice

Simultaneously gesture recognizer choice
  • Loading branch information
gblancogarcia committed Jul 18, 2015
2 parents 009b2d1 + aa8248a commit 05d2d90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ typedef NS_ENUM(NSInteger, GBScrollDirection) {
*/
@property (nonatomic, getter = isTapEnabled) BOOL tapEnabled;

/**
* Whether to use GBInfiniteScrollViews UIPanGestureRecognizer or not.
* If enabled, the simultaneously gesture recognizer usage will be enabled.
* This can result in unwanted scroll delegation behavior if you use the GBInfiniteScrollView above other UIScrollViews as the touch input is delegated to these UIScrollViews too.
* Default value YES.
*/
@property (nonatomic) BOOL useInfiniteScrollPanGestureRecognizer;

/**
* Gets the current view.
*
Expand Down
39 changes: 33 additions & 6 deletions GBInfiniteScrollView/GBInfiniteScrollView/GBInfiniteScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ @interface GBInfiniteScrollView () <UIGestureRecognizerDelegate>
*/
@property (nonatomic) BOOL shouldScrollPreviousPage;

@property (nonatomic, strong) UIPanGestureRecognizer *infiniteScrollViewPanGestureRecognizer;


@property (nonatomic) BOOL needsUpdatePageIndex;
@property (nonatomic) NSUInteger newPageIndex;
Expand Down Expand Up @@ -434,11 +436,7 @@ - (void)setUp
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
self.userInteractionEnabled = YES;

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self
action:@selector(panOnScrollView:)];
pan.delegate = self;
[self addGestureRecognizer:pan];
self.useInfiniteScrollPanGestureRecognizer = YES;

[self setupTapGesture];

Expand All @@ -463,6 +461,20 @@ - (void)setupTapGesture
}
}

- (void)setupPanGesture
{
if (self.isDebugModeOn && self.isVerboseDebugModeOn) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}

if (self.useInfiniteScrollPanGestureRecognizer) {
self.infiniteScrollViewPanGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self
action:@selector(panOnScrollView:)];
self.infiniteScrollViewPanGestureRecognizer.delegate = self;
[self addGestureRecognizer:self.infiniteScrollViewPanGestureRecognizer];
}
}

- (void)setUpDefautValues
{
if (self.isDebugModeOn && self.isVerboseDebugModeOn) {
Expand Down Expand Up @@ -518,6 +530,20 @@ - (void)setTapEnabled:(BOOL)tapEnabled {
[self setupTapGesture];
}

- (void)setUseInfiniteScrollPanGestureRecognizer:(BOOL)useInfiniteScrollPanGestureRecognizer
{
_useInfiniteScrollPanGestureRecognizer = useInfiniteScrollPanGestureRecognizer;

if (self.useInfiniteScrollPanGestureRecognizer) {
if (self.infiniteScrollViewPanGestureRecognizer == nil) {
[self setupPanGesture];
}
} else {
[self removeGestureRecognizer:self.infiniteScrollViewPanGestureRecognizer];
self.infiniteScrollViewPanGestureRecognizer = nil;
}
}

#pragma mark - Tap

- (void)tapOnScrollView
Expand Down Expand Up @@ -1782,7 +1808,8 @@ - (void)scrollToPageAtIndex:(NSUInteger)index animated:(BOOL)animated

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
//If the usage of the UIPanGestureRecognizer is enabled, we need to enable simultaneously gesture recognizing. If not, it's not needed.
return self.useInfiniteScrollPanGestureRecognizer;
}


Expand Down

0 comments on commit 05d2d90

Please sign in to comment.