Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support notification for Slide Menu animations #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions SlideMenu/Source/SlideNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down