From 439a6d76aada477749e6df5d8644959796271bfe Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Fri, 7 Feb 2014 13:07:26 -0800 Subject: [PATCH] - Added bounce functionality (Let's say the right menu is for notifications, when you receive notification you bounce the right menu to let the user know that they should open the right menu to view the notification) --- SlideMenu/Helper Classes/HomeViewController.h | 2 + SlideMenu/Helper Classes/HomeViewController.m | 11 ++++ SlideMenu/Source/SlideNavigationController.h | 1 + SlideMenu/Source/SlideNavigationController.m | 55 +++++++++++++++---- .../en.lproj/MainStoryboard_iPhone.storyboard | 14 ++++- 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/SlideMenu/Helper Classes/HomeViewController.h b/SlideMenu/Helper Classes/HomeViewController.h index 0afd2cb..c0a1ef1 100755 --- a/SlideMenu/Helper Classes/HomeViewController.h +++ b/SlideMenu/Helper Classes/HomeViewController.h @@ -11,4 +11,6 @@ @interface HomeViewController : UIViewController +- (IBAction)bounceMenu:(id)sender; + @end diff --git a/SlideMenu/Helper Classes/HomeViewController.m b/SlideMenu/Helper Classes/HomeViewController.m index 46d7fa7..97fbd71 100755 --- a/SlideMenu/Helper Classes/HomeViewController.m +++ b/SlideMenu/Helper Classes/HomeViewController.m @@ -27,4 +27,15 @@ return YES; } +#pragma mark - IBActions - + +- (IBAction)bounceMenu:(id)sender +{ + static Menu menu = MenuLeft; + + [[SlideNavigationController sharedInstance] bounceMenu:menu withCompletion:nil]; + + menu = (menu == MenuLeft) ? MenuRight : MenuLeft; +} + @end diff --git a/SlideMenu/Source/SlideNavigationController.h b/SlideMenu/Source/SlideNavigationController.h index 9b4bd49..8471996 100644 --- a/SlideMenu/Source/SlideNavigationController.h +++ b/SlideMenu/Source/SlideNavigationController.h @@ -54,6 +54,7 @@ typedef enum{ + (SlideNavigationController *)sharedInstance; - (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion; +- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion; - (void)openMenu:(Menu)menu withCompletion:(void (^)())completion; - (void)closeMenuWithCompletion:(void (^)())completion; - (void)toggleLeftMenu; diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index b355a09..48fa3be 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -136,19 +136,41 @@ static SlideNavigationController *singletonInstance; self.view.layer.shadowOpacity = MENU_SHADOW_OPACITY; } -- (void)updateMenuFrameAndTransformAccordingToOrientation -{ - // Animate rotatation when menu is open and device rotates - CGAffineTransform transform = self.view.transform; - self.leftMenu.view.transform = transform; - self.rightMenu.view.transform = transform; - - self.leftMenu.view.frame = [self initialRectForMenu]; - self.rightMenu.view.frame = [self initialRectForMenu]; -} - #pragma mark - Public Methods - +- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion +{ + [self prepareMenuForReveal:menu forcePrepare:YES]; + NSInteger movementDirection = (menu == MenuLeft) ? 1 : -1; + + [UIView animateWithDuration:.16 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + [self moveHorizontallyToLocation:30*movementDirection]; + } completion:^(BOOL finished){ + [UIView animateWithDuration:.1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ + [self moveHorizontallyToLocation:0]; + } completion:^(BOOL finished){ + [UIView animateWithDuration:.12 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + [self moveHorizontallyToLocation:16*movementDirection]; + } completion:^(BOOL finished){ + [UIView animateWithDuration:.08 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ + [self moveHorizontallyToLocation:0]; + } completion:^(BOOL finished){ + [UIView animateWithDuration:.08 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ + [self moveHorizontallyToLocation:6*movementDirection]; + } completion:^(BOOL finished){ + [UIView animateWithDuration:.06 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ + [self moveHorizontallyToLocation:0]; + } completion:^(BOOL finished){ + if (completion) + completion(); + }]; + }]; + }]; + }]; + }]; + }]; +} + - (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion { if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class]) @@ -262,6 +284,17 @@ static SlideNavigationController *singletonInstance; #pragma mark - Private Methods - +- (void)updateMenuFrameAndTransformAccordingToOrientation +{ + // Animate rotatation when menu is open and device rotates + CGAffineTransform transform = self.view.transform; + self.leftMenu.view.transform = transform; + self.rightMenu.view.transform = transform; + + self.leftMenu.view.frame = [self initialRectForMenu]; + self.rightMenu.view.frame = [self initialRectForMenu]; +} + - (void)enableTapGestureToCloseMenu:(BOOL)enable { if (enable) diff --git a/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard b/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard index 2ac4a4c..c0941cc 100755 --- a/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard +++ b/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard @@ -94,9 +94,9 @@