Skip to content

Commit 437270a

Browse files
aryaxtAryan
authored andcommitted
Fixed issue where sometimes when swiping really quick it's possible to see the wrong menu
1 parent 2a6be6a commit 437270a

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

SlideMenu/Source/SlideNavigationController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
@end
3636

3737
typedef enum{
38-
MenuLeft,
39-
MenuRight,
38+
MenuLeft = 1,
39+
MenuRight = 2
4040
}Menu;
4141

4242
@protocol SlideNavigationContorllerAnimator;

SlideMenu/Source/SlideNavigationController.m

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ @interface SlideNavigationController() <UIGestureRecognizerDelegate>
3737
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
3838
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
3939
@property (nonatomic, assign) CGPoint draggingPoint;
40+
@property (nonatomic, assign) Menu lastRevealedMenu;
4041
@end
4142

4243
@implementation SlideNavigationController
@@ -147,7 +148,7 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
147148

148149
- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion
149150
{
150-
[self prepareMenuForReveal:menu forcePrepare:YES];
151+
[self prepareMenuForReveal:menu];
151152
NSInteger movementDirection = (menu == MenuLeft) ? 1 : -1;
152153

153154
[UIView animateWithDuration:.16 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
@@ -446,8 +447,8 @@ - (BOOL)shouldDisplayMenu:(Menu)menu forViewController:(UIViewController *)vc
446447
- (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)())completion
447448
{
448449
[self enableTapGestureToCloseMenu:YES];
449-
450-
[self prepareMenuForReveal:menu forcePrepare:NO];
450+
451+
[self prepareMenuForReveal:menu];
451452

452453
[UIView animateWithDuration:duration
453454
delay:0
@@ -542,14 +543,16 @@ - (CGRect)initialRectForMenu
542543
return rect;
543544
}
544545

545-
- (void)prepareMenuForReveal:(Menu)menu forcePrepare:(BOOL)forcePrepare
546+
- (void)prepareMenuForReveal:(Menu)menu
546547
{
547-
UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu;
548+
// Only prepare menu if it has changed (ex: from MenuLeft to MenuRight or vice versa)
549+
if (self.lastRevealedMenu && menu == self.lastRevealedMenu)
550+
return;
551+
552+
UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu;
548553
UIViewController *removingMenuViewController = (menu == MenuLeft) ? self.rightMenu : self.leftMenu;
549-
550-
// If menu is already open don't prepare, unless forcePrepare is set to true
551-
if ([self isMenuOpen] && !forcePrepare)
552-
return;
554+
555+
self.lastRevealedMenu = menu;
553556

554557
[removingMenuViewController.view removeFromSuperview];
555558
[self.view.window insertSubview:menuViewController.view atIndex:0];
@@ -658,35 +661,32 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
658661
CGPoint velocity = [aPanRecognizer velocityInView:aPanRecognizer.view];
659662
NSInteger movement = translation.x - self.draggingPoint.x;
660663

661-
static Menu lastMenu;
662-
Menu menu = (self.horizontalLocation > 0 || (self.horizontalLocation == 0 && movement > 0) ) ? MenuLeft : MenuRight;
663-
664+
Menu currentMenu;
665+
666+
if (self.horizontalLocation > 0)
667+
currentMenu = MenuLeft;
668+
else if (self.horizontalLocation < 0)
669+
currentMenu = MenuRight;
670+
else
671+
currentMenu = (translation.x > 0) ? MenuLeft : MenuRight;
672+
673+
[self prepareMenuForReveal:currentMenu];
674+
664675
if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
665676
{
666-
if (![self isMenuOpen])
667-
[self prepareMenuForReveal:menu forcePrepare:YES];
668-
669677
self.draggingPoint = translation;
670-
lastMenu = menu;
671678
}
672679
else if (aPanRecognizer.state == UIGestureRecognizerStateChanged)
673680
{
674681
static CGFloat lastHorizontalLocation = 0;
675682
CGFloat newHorizontalLocation = [self horizontalLocation];
676-
677-
// Force prepare menu when slides quickly between left and right menu
678-
if (lastMenu != menu)
679-
[self prepareMenuForReveal:menu forcePrepare:YES];
680-
681683
lastHorizontalLocation = newHorizontalLocation;
682-
683684
newHorizontalLocation += movement;
684685

685686
if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging)
686687
[self moveHorizontallyToLocation:newHorizontalLocation];
687688

688689
self.draggingPoint = translation;
689-
lastMenu = menu;
690690
}
691691
else if (aPanRecognizer.state == UIGestureRecognizerStateEnded)
692692
{
@@ -733,8 +733,6 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
733733
else
734734
[self openMenu:(currentX > 0) ? MenuLeft : MenuRight withCompletion:nil];
735735
}
736-
737-
lastMenu = -1;
738736
}
739737
}
740738

0 commit comments

Comments
 (0)