@@ -46,6 +46,7 @@ @implementation SlideNavigationController
4646#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
4747#define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100
4848#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .8
49+ #define MENU_REVEAL_ANIMATION_DEFAULT_SCALE_MINIMUM_SCALE .85
4950#define STATUS_BAR_HEIGHT 20
5051
5152static SlideNavigationController *singletonInstance;
@@ -90,6 +91,7 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController
9091- (void )setup
9192{
9293 self.menuRevealAnimationSlideMovement = MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT;
94+ self.menuRevealAnimationScaleMinScale = MENU_REVEAL_ANIMATION_DEFAULT_SCALE_MINIMUM_SCALE;
9395 self.menuRevealAnimationFadeMaximumAlpha = MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA;
9496 self.menuRevealAnimation = MenuRevealAnimationSlideAndFade;
9597 self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
@@ -106,6 +108,7 @@ - (void)setup
106108 self.view .layer .rasterizationScale = [UIScreen mainScreen ].scale ;
107109
108110 [self setEnableSwipeGesture: YES ];
111+ [self updateMenuFrameAndTransformAccordingToOrientation ];
109112}
110113
111114- (void )viewWillLayoutSubviews
@@ -120,9 +123,6 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
120123{
121124 [super willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
122125
123- // Update rotation animation
124- [self updateMenuFrameAndTransformAccordingToOrientation ];
125-
126126 // Avoid an ugnly shadow in background while rotating
127127 self.view .layer .shadowOpacity = 0 ;
128128}
@@ -131,6 +131,9 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
131131{
132132 [super didRotateFromInterfaceOrientation: fromInterfaceOrientation];
133133
134+ // Update rotation animation
135+ [self updateMenuFrameAndTransformAccordingToOrientation ];
136+
134137 self.view .layer .shadowPath = [UIBezierPath bezierPathWithRect: self .view.bounds].CGPath ;
135138
136139 // we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back
@@ -139,17 +142,13 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
139142
140143- (void )updateMenuFrameAndTransformAccordingToOrientation
141144{
145+ // Animate rotatation when menu is open and device rotates
142146 CGAffineTransform transform = self.view .transform ;
143147 self.leftMenu .view .transform = transform;
144148 self.rightMenu .view .transform = transform;
145149
146- CGRect rect = self.view .frame ;
147- self.leftMenu .view .frame = rect;
148- self.rightMenu .view .frame = rect;
149-
150- // Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation
151- [self updateMenuAnimation: MenuLeft];
152- [self updateMenuAnimation: MenuRight];
150+ self.leftMenu .view .frame = [self initialRectForMenu ];
151+ self.rightMenu .view .frame = [self initialRectForMenu ];
153152}
154153
155154#pragma mark - Public Methods -
@@ -386,14 +385,17 @@ - (void)updateMenuAnimation:(Menu)menu
386385 ? (self.horizontalLocation / self.maxXForDragging )
387386 : (self.horizontalLocation / self.minXForDragging );
388387
389- if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
388+ if (self.menuRevealAnimation == MenuRevealAnimationFade ||
389+ self.menuRevealAnimation == MenuRevealAnimationSlideAndFade ||
390+ self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
390391 {
391392 self.menuRevealFadeAnimationView .frame = menuViewController.view .bounds ;
392393 [menuViewController.view addSubview: self .menuRevealFadeAnimationView];
393394 self.menuRevealFadeAnimationView .alpha = self.menuRevealAnimationFadeMaximumAlpha - (self.menuRevealAnimationFadeMaximumAlpha *progress);
394395 }
395396
396- if (self.menuRevealAnimation == MenuRevealAnimationSlide || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
397+ if (self.menuRevealAnimation == MenuRevealAnimationSlide ||
398+ self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
397399 {
398400 NSInteger location = (menu == MenuLeft)
399401 ? (self.menuRevealAnimationSlideMovement * -1 ) + (self.menuRevealAnimationSlideMovement * progress)
@@ -405,34 +407,56 @@ - (void)updateMenuAnimation:(Menu)menu
405407 if (menu == MenuRight)
406408 location = (location < 0 ) ? 0 : location;
407409
408- CGRect rect = menuViewController.view .frame ;
409- BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (@" 7.0" );
410+ CGRect rect = [self initialRectForMenu ];
410411
411412 if (UIInterfaceOrientationIsLandscape (self.interfaceOrientation ))
412413 {
413414 rect.origin .y = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? location : location*-1 ;
414-
415- if (!isIos7)
416- {
417- // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
418- rect.origin .x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT;
419- rect.size .width = self.view .frame .size .width -STATUS_BAR_HEIGHT;
420- }
421415 }
422416 else
423417 {
424418 rect.origin .x = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? location : location*-1 ;
425-
426- if (!isIos7)
427- {
428- // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
429- rect.origin .y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0 ;
430- rect.size .height = self.view .frame .size .height -STATUS_BAR_HEIGHT;
431- }
432419 }
433420
434421 menuViewController.view .frame = rect;
435422 }
423+
424+ if (self.menuRevealAnimation == MenuRevealAnimationScale ||
425+ self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
426+ {
427+ CGFloat scale = MIN (1 , (1 -self.menuRevealAnimationScaleMinScale ) *progress + self.menuRevealAnimationScaleMinScale );
428+ menuViewController.view .transform = CGAffineTransformScale (self.view .transform , scale, scale);
429+ }
430+ }
431+
432+ - (CGRect)initialRectForMenu
433+ {
434+ CGRect rect = self.view .frame ;
435+ rect.origin .x = 0 ;
436+ rect.origin .y = 0 ;
437+
438+ BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (@" 7.0" );
439+
440+ if (UIInterfaceOrientationIsLandscape (self.interfaceOrientation ))
441+ {
442+ if (!isIos7)
443+ {
444+ // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
445+ rect.origin .x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT;
446+ rect.size .width = self.view .frame .size .width -STATUS_BAR_HEIGHT;
447+ }
448+ }
449+ else
450+ {
451+ if (!isIos7)
452+ {
453+ // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20
454+ rect.origin .y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0 ;
455+ rect.size .height = self.view .frame .size .height -STATUS_BAR_HEIGHT;
456+ }
457+ }
458+
459+ return rect;
436460}
437461
438462- (void )prepareMenuForReveal : (Menu)menu forcePrepare : (BOOL )forcePrepare
@@ -444,19 +468,22 @@ - (void)prepareMenuForReveal:(Menu)menu forcePrepare:(BOOL)forcePrepare
444468 UIViewController *menuViewController = (menu == MenuLeft) ? self.leftMenu : self.rightMenu ;
445469 UIViewController *removingMenuViewController = (menu == MenuLeft) ? self.rightMenu : self.leftMenu ;
446470
447- [self updateMenuFrameAndTransformAccordingToOrientation ];
471+ // [self updateMenuFrameAndTransformAccordingToOrientation];
448472
449473 // If already has been added to the view (has superview) it means it has been initialized so avoid reinitializing
450474 if (menuViewController.view .superview )
451475 return ;
452476
453- if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
477+ if (self.menuRevealAnimation == MenuRevealAnimationFade ||
478+ self.menuRevealAnimation == MenuRevealAnimationSlideAndFade ||
479+ self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
454480 {
455481 self.menuRevealFadeAnimationView .alpha = self.menuRevealAnimationFadeMaximumAlpha ;
456482 self.menuRevealFadeAnimationView .frame = menuViewController.view .bounds ;
457483 }
458484
459- if (self.menuRevealAnimation == MenuRevealAnimationSlide || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
485+ if (self.menuRevealAnimation == MenuRevealAnimationSlide ||
486+ self.menuRevealAnimation == MenuRevealAnimationSlideAndFade)
460487 {
461488 CGRect rect = menuViewController.view .frame ;
462489
@@ -486,6 +513,12 @@ - (void)prepareMenuForReveal:(Menu)menu forcePrepare:(BOOL)forcePrepare
486513 menuViewController.view .frame = rect;
487514 }
488515
516+ if (self.menuRevealAnimation == MenuRevealAnimationScale ||
517+ self.menuRevealAnimation == MenuRevealAnimationScaleAndFade)
518+ {
519+ menuViewController.view .transform = CGAffineTransformScale (self.view .transform , self.menuRevealAnimationScaleMinScale , self.menuRevealAnimationScaleMinScale );
520+ }
521+
489522 [removingMenuViewController.view removeFromSuperview ];
490523 [self .view.window insertSubview: menuViewController.view atIndex: 0 ];
491524}
@@ -581,7 +614,9 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
581614
582615 if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
583616 {
584- [self prepareMenuForReveal: menu forcePrepare: YES ];
617+ if (![self isMenuOpen ])
618+ [self prepareMenuForReveal: menu forcePrepare: YES ];
619+
585620 self.draggingPoint = translation;
586621 lastMenu = menu;
587622 }
@@ -728,4 +763,11 @@ - (void)setMenuRevealAnimationFadeColor:(UIColor *)menuRevealAnimationFadeColor
728763 self.menuRevealFadeAnimationView .backgroundColor = menuRevealAnimationFadeColor;
729764}
730765
766+ - (void )setMenuRevealAnimation : (MenuRevealAnimation)menuRevealAnimation
767+ {
768+ _menuRevealAnimation = menuRevealAnimation;
769+
770+ [self updateMenuFrameAndTransformAccordingToOrientation ];
771+ }
772+
731773@end
0 commit comments