Added new methods used for switching between ViewControllers and deprecated switchToViewController:withCompletion:. These new methods have more meaningfull names and decribe exactly what happends during a switch. You can also disable slide out animation using these new methods

This commit is contained in:
Aryan Ghassemi 2014-04-19 10:43:17 -07:00
parent d1281e7361
commit 38f6bb528c
3 changed files with 83 additions and 21 deletions

View File

@ -120,7 +120,7 @@
break;
}
[[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
[[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:vc withCompletion:nil];
}
else
{

View File

@ -53,7 +53,11 @@ typedef enum{
@property (nonatomic, strong) id <SlideNavigationContorllerAnimator> menuRevealAnimator;
+ (SlideNavigationController *)sharedInstance;
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion __deprecated;
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
- (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)bounceMenu:(Menu)menu withCompletion:(void (^)())completion;
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion;
- (void)closeMenuWithCompletion:(void (^)())completion;

View File

@ -28,6 +28,11 @@
#import "SlideNavigationController.h"
#import "SlideNavigationContorllerAnimator.h"
typedef enum {
PopTypeAll,
PopTypeRoot
} PopType;
@interface SlideNavigationController()
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
@ -171,7 +176,10 @@ static SlideNavigationController *singletonInstance;
}];
}
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
- (void)switchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
popType:(PopType)poptype
andCompletion:(void (^)())completion
{
if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class])
{
@ -179,36 +187,86 @@ static SlideNavigationController *singletonInstance;
return;
}
if ([self isMenuOpen])
{
[UIView animateWithDuration:MENU_SLIDE_ANIMATION_DURATION
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGFloat width = self.horizontalSize;
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
[self moveHorizontallyToLocation:moveLocation];
} completion:^(BOOL finished) {
void (^switchAndCallCompletion)(BOOL) = ^(BOOL closeMenuBeforeCallingCompletion) {
if (poptype == PopTypeAll) {
[self setViewControllers:@[viewController]];
}
else {
[super popToRootViewControllerAnimated: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) ? MENU_SLIDE_ANIMATION_DURATION : 0
delay:0
options:UIViewAnimationOptionCurveEaseOut
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
{
[super popToRootViewControllerAnimated:NO];
[super pushViewController:viewController animated:YES];
if (completion)
completion();
switchAndCallCompletion(NO);
}
}
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion];
}
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
andCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeRoot andCompletion:completion];
}
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController
withCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion];
}
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController
withSlideOutAnimation:(BOOL)slideOutAnimation
andCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeAll andCompletion:completion];
}
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController
withCompletion:(void (^)())completion
{
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeAll andCompletion:completion];
}
- (void)closeMenuWithCompletion:(void (^)())completion
{
[self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];