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

added support for Main & Specific controller #247

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions SlideMenu/Source/SlideNavigationController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ extern NSString *const SlideNavigationControllerDidReveal;
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
- (void)popToMainAndSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
- (void)popToMainAndSwitchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
- (void)popToController:(UIViewController *)goToController andSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
- (void)popToController:(UIViewController *)goToController andSwitchToViewController:(UIViewController *)viewController andCompletion:(void (^)())completion;

- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion;
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion;
- (void)closeMenuWithCompletion:(void (^)())completion;
Expand Down
95 changes: 95 additions & 0 deletions SlideMenu/Source/SlideNavigationController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

typedef enum {
PopTypeAll,
PopTypeMain,
PopTypeController,
PopTypeRoot
} PopType;

Expand Down Expand Up @@ -222,6 +224,12 @@ - (void)switchToViewController:(UIViewController *)viewController
if (poptype == PopTypeAll) {
[self setViewControllers:@[viewController]];
}
else if (poptype == PopTypeMain){
NSArray *arr = [self viewControllers];

[super popToViewController:[arr objectAtIndex:1] animated:NO];
[super pushViewController:viewController animated:NO];
}
else {
[super popToRootViewControllerAnimated:NO];
[super pushViewController:viewController animated:NO];
Expand Down Expand Up @@ -267,6 +275,64 @@ - (void)switchToViewController:(UIViewController *)viewController
}
}

- (void) popToViewController:(UIViewController *)goToController
andSwitchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
popType:(PopType)poptype
andCompletion:(void (^)())completion
{
if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class])
{
[self closeMenuWithCompletion:completion];
return;
}

void (^switchAndCallCompletion)(BOOL) = ^(BOOL closeMenuBeforeCallingCompletion) {
if (poptype == PopTypeController){
[super popToViewController:goToController animated:NO];
[super pushViewController:viewController animated:NO];
}

if (closeMenuBeforeCallingCompletion)
{
[self closeMenuWithCompletion:^{
if (completion)
completion();
}];
}
else
{
if (completion)
completion();
}
};

if ([self isMenuOpen])
{
if (slideOutAnimation)
{
[UIView animateWithDuration:(slideOutAnimation) ? self.menuRevealAnimationDuration : 0
delay:0
options:self.menuRevealAnimationOption
animations:^{
CGFloat width = self.horizontalSize;
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
[self moveHorizontallyToLocation:moveLocation];
} completion:^(BOOL finished) {
switchAndCallCompletion(YES);
}];
}
else
{
switchAndCallCompletion(YES);
}
}
else
{
switchAndCallCompletion(NO);
}
}

- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion];
Expand Down Expand Up @@ -298,6 +364,35 @@ - (void)popAllAndSwitchToViewController:(UIViewController *)viewController
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeAll andCompletion:completion];
}


- (void)popToMainAndSwitchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
andCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeMain andCompletion:completion];
}

- (void)popToMainAndSwitchToViewController:(UIViewController *)viewController
withCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeMain andCompletion:completion];
}

- (void) popToController:(UIViewController *)goToController
andSwitchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
andCompletion:(void (^)())completion
{
[self popToViewController:goToController andSwitchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeController andCompletion:completion];
}

- (void) popToController:(UIViewController *)goToController
andSwitchToViewController:(UIViewController *)viewController
withCompletion:(void (^)())completion
{
[self popToViewController:goToController andSwitchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeController andCompletion:completion];
}

- (void)closeMenuWithCompletion:(void (^)())completion
{
[self closeMenuWithDuration:self.menuRevealAnimationDuration andCompletion:completion];
Expand Down