@@ -45,7 +45,7 @@ @implementation SlideNavigationController
4545#define MENU_DEFAULT_SLIDE_OFFSET 60
4646#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
4747#define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100
48- #define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .7
48+ #define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .8
4949#define STATUS_BAR_HEIGHT 20
5050
5151static SlideNavigationController *singletonInstance;
@@ -111,13 +111,18 @@ - (void)setup
111111- (void )viewWillLayoutSubviews
112112{
113113 [super viewWillLayoutSubviews ];
114-
114+
115+ // Update shadow size
116+ self.view .layer .shadowPath = [UIBezierPath bezierPathWithRect: self .view.bounds].CGPath ;
115117}
116118
117119- (void )willRotateToInterfaceOrientation : (UIInterfaceOrientation)toInterfaceOrientation duration : (NSTimeInterval )duration
118120{
119121 [super willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
120122
123+ // Update rotation animation
124+ [self updateMenuFrameAndTransformAccordingToOrientation ];
125+
121126 // Avoid an ugnly shadow in background while rotating
122127 self.view .layer .shadowOpacity = 0 ;
123128}
@@ -126,6 +131,14 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
126131{
127132 [super didRotateFromInterfaceOrientation: fromInterfaceOrientation];
128133
134+ self.view .layer .shadowPath = [UIBezierPath bezierPathWithRect: self .view.bounds].CGPath ;
135+
136+ // we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
137+ self.view .layer .shadowOpacity = MENU_SHADOW_OPACITY;
138+ }
139+
140+ - (void )updateMenuFrameAndTransformAccordingToOrientation
141+ {
129142 CGAffineTransform transform = self.view .transform ;
130143 self.leftMenu .view .transform = transform;
131144 self.rightMenu .view .transform = transform;
@@ -137,11 +150,6 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
137150 // Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation
138151 [self updateMenuAnimation: MenuLeft];
139152 [self updateMenuAnimation: MenuRight];
140-
141- self.view .layer .shadowPath = [UIBezierPath bezierPathWithRect: self .view.bounds].CGPath ;
142-
143- // we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
144- self.view .layer .shadowOpacity = MENU_SHADOW_OPACITY;
145153}
146154
147155#pragma mark - Public Methods -
@@ -311,7 +319,7 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
311319{
312320 [self .topViewController.view addGestureRecognizer: self .tapRecognizer];
313321
314- [self prepareMenuForReveal: menu];
322+ [self prepareMenuForReveal: menu forcePrepare: NO ];
315323
316324 [UIView animateWithDuration: duration
317325 delay: 0
@@ -427,11 +435,17 @@ - (void)updateMenuAnimation:(Menu)menu
427435 }
428436}
429437
430- - (void )prepareMenuForReveal : (Menu)menu
438+ - (void )prepareMenuForReveal : (Menu)menu forcePrepare : ( BOOL ) forcePrepare
431439{
440+ // If menu is already open don't prepare, unless forcePrepare is set to true
441+ if ([self isMenuOpen ] && !forcePrepare)
442+ return ;
443+
432444 UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu ;
433445 UIViewController *removingMenuViewController = (menu == MenuLeft) ? self.rightMenu : self.leftMenu ;
434446
447+ [self updateMenuFrameAndTransformAccordingToOrientation ];
448+
435449 // If already has been added to the view (has superview) it means it has been initialized so avoid reinitializing
436450 if (menuViewController.view .superview )
437451 return ;
@@ -562,15 +576,25 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
562576 CGPoint velocity = [aPanRecognizer velocityInView: aPanRecognizer.view];
563577 NSInteger movement = translation.x - self.draggingPoint .x ;
564578
565- [ self prepareMenuForReveal: (self .horizontalLocation > 0 || (self .horizontalLocation == 0 && translation.x > 0 ) ) ? MenuLeft : MenuRight] ;
579+ Menu menu = (self.horizontalLocation > 0 || (self.horizontalLocation == 0 && translation.x > 0 ) ) ? MenuLeft : MenuRight;
566580
567581 if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
568582 {
583+ [self prepareMenuForReveal: menu forcePrepare: YES ];
569584 self.draggingPoint = translation;
570585 }
571586 else if (aPanRecognizer.state == UIGestureRecognizerStateChanged)
572587 {
573- NSInteger newHorizontalLocation = [self horizontalLocation ];
588+ static CGFloat lastHorizontalLocation = 0 ;
589+ CGFloat newHorizontalLocation = [self horizontalLocation ];
590+
591+ // Force prepare menu when slides quickly between left and right menu
592+ if ((lastHorizontalLocation < 0 && newHorizontalLocation > 0 ) ||
593+ (lastHorizontalLocation > 0 && newHorizontalLocation < 0 ))
594+ [self prepareMenuForReveal: menu forcePrepare: YES ];
595+
596+ lastHorizontalLocation = newHorizontalLocation;
597+
574598 newHorizontalLocation += movement;
575599
576600 if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging )
0 commit comments