From 893c4d71d013f7dee6c2ca6a008f6bbf7d3169f7 Mon Sep 17 00:00:00 2001 From: dungntm58 Date: Thu, 27 Sep 2018 14:04:14 +0700 Subject: [PATCH] Fix animations --- SlideMenu/Source/SlideNavigationController.m | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index d7409a6..e545829 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -46,6 +46,7 @@ @implementation SlideNavigationController NSString * const SlideNavigationControllerDidOpen = @"SlideNavigationControllerDidOpen"; NSString * const SlideNavigationControllerDidClose = @"SlideNavigationControllerDidClose"; NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal"; +NSString *const SlideNavigationControllerWillChangeLocation = @"SlideNavigationControllerWillChangeLocation"; #define MENU_SLIDE_ANIMATION_DURATION .3 #define MENU_SLIDE_ANIMATION_OPTION UIViewAnimationOptionCurveEaseOut @@ -245,6 +246,9 @@ - (void)switchToViewController:(UIViewController *)viewController { if (slideOutAnimation) { + CGFloat width = self.horizontalSize; + CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width; + [self postLocationNotification:moveLocation duration: slideOutAnimation]; [UIView animateWithDuration:(slideOutAnimation) ? self.menuRevealAnimationDuration : 0 delay:0 options:self.menuRevealAnimationOption @@ -478,7 +482,9 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^) [self enableTapGestureToCloseMenu:YES]; [self prepareMenuForReveal:menu]; - + + CGFloat width = self.horizontalSize; + [self postLocationNotification:(width - self.slideOffset) duration: duration]; [UIView animateWithDuration:duration delay:0 options:self.menuRevealAnimationOption @@ -501,7 +507,8 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi [self enableTapGestureToCloseMenu:NO]; Menu menu = (self.horizontalLocation > 0) ? MenuLeft : MenuRight; - + + [self postLocationNotification:0 duration: duration]; [UIView animateWithDuration:duration delay:0 options:self.menuRevealAnimationOption @@ -663,6 +670,12 @@ - (void)postNotificationWithName:(NSString *)name forMenu:(Menu)menu [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:userInfo]; } +- (void)postLocationNotification:(CGFloat)location duration:(CGFloat)duration +{ + NSDictionary *userInfo = @{ @"location" : [NSNumber numberWithFloat:location], @"duration" : [NSNumber numberWithFloat:duration] }; + [[NSNotificationCenter defaultCenter] postNotificationName:SlideNavigationControllerWillChangeLocation object:nil userInfo:userInfo]; +} + #pragma mark - UINavigationControllerDelegate Methods - - (void)navigationController:(UINavigationController *)navigationController @@ -753,7 +766,10 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer newHorizontalLocation += movement; if (newHorizontalLocation >= self.minXForDragging && newHorizontalLocation <= self.maxXForDragging) - [self moveHorizontallyToLocation:newHorizontalLocation]; + { + [self moveHorizontallyToLocation:newHorizontalLocation]; + [self postLocationNotification:newHorizontalLocation duration: 0]; + } self.draggingPoint = translation; }