Skip to content

Commit 38f6bb5

Browse files
committed
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
1 parent d1281e7 commit 38f6bb5

File tree

3 files changed

+83
-21
lines changed

3 files changed

+83
-21
lines changed

SlideMenu/Helper Classes/MenuViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
120120
break;
121121
}
122122

123-
[[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
123+
[[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:vc withCompletion:nil];
124124
}
125125
else
126126
{

SlideMenu/Source/SlideNavigationController.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ typedef enum{
5353
@property (nonatomic, strong) id <SlideNavigationContorllerAnimator> menuRevealAnimator;
5454

5555
+ (SlideNavigationController *)sharedInstance;
56-
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
56+
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion __deprecated;
57+
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
58+
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
59+
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController withSlideOutAnimation:(BOOL)slideOutAnimation andCompletion:(void (^)())completion;
60+
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion;
5761
- (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion;
5862
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion;
5963
- (void)closeMenuWithCompletion:(void (^)())completion;

SlideMenu/Source/SlideNavigationController.m

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#import "SlideNavigationController.h"
2929
#import "SlideNavigationContorllerAnimator.h"
3030

31+
typedef enum {
32+
PopTypeAll,
33+
PopTypeRoot
34+
} PopType;
35+
3136
@interface SlideNavigationController()
3237
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
3338
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
@@ -171,44 +176,97 @@ - (void)bounceMenu:(Menu)menu withCompletion:(void (^)())completion
171176
}];
172177
}
173178

174-
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
179+
- (void)switchToViewController:(UIViewController *)viewController
180+
withSlideOutAnimation:(BOOL)slideOutAnimation
181+
popType:(PopType)poptype
182+
andCompletion:(void (^)())completion
175183
{
176184
if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class])
177185
{
178186
[self closeMenuWithCompletion:completion];
179187
return;
180188
}
181189

182-
if ([self isMenuOpen])
183-
{
184-
[UIView animateWithDuration:MENU_SLIDE_ANIMATION_DURATION
185-
delay:0
186-
options:UIViewAnimationOptionCurveEaseOut
187-
animations:^{
188-
CGFloat width = self.horizontalSize;
189-
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
190-
[self moveHorizontallyToLocation:moveLocation];
191-
} completion:^(BOOL finished) {
192-
190+
void (^switchAndCallCompletion)(BOOL) = ^(BOOL closeMenuBeforeCallingCompletion) {
191+
if (poptype == PopTypeAll) {
192+
[self setViewControllers:@[viewController]];
193+
}
194+
else {
193195
[super popToRootViewControllerAnimated:NO];
194196
[super pushViewController:viewController animated:NO];
195-
197+
}
198+
199+
if (closeMenuBeforeCallingCompletion)
200+
{
196201
[self closeMenuWithCompletion:^{
197202
if (completion)
198203
completion();
199204
}];
200-
}];
205+
}
206+
else
207+
{
208+
if (completion)
209+
completion();
210+
}
211+
};
212+
213+
if ([self isMenuOpen])
214+
{
215+
if (slideOutAnimation)
216+
{
217+
[UIView animateWithDuration:(slideOutAnimation) ? MENU_SLIDE_ANIMATION_DURATION : 0
218+
delay:0
219+
options:UIViewAnimationOptionCurveEaseOut
220+
animations:^{
221+
CGFloat width = self.horizontalSize;
222+
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
223+
[self moveHorizontallyToLocation:moveLocation];
224+
} completion:^(BOOL finished) {
225+
switchAndCallCompletion(YES);
226+
}];
227+
}
228+
else
229+
{
230+
switchAndCallCompletion(YES);
231+
}
201232
}
202233
else
203234
{
204-
[super popToRootViewControllerAnimated:NO];
205-
[super pushViewController:viewController animated:YES];
206-
207-
if (completion)
208-
completion();
235+
switchAndCallCompletion(NO);
209236
}
210237
}
211238

239+
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
240+
{
241+
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion];
242+
}
243+
244+
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController
245+
withSlideOutAnimation:(BOOL)slideOutAnimation
246+
andCompletion:(void (^)())completion
247+
{
248+
[self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeRoot andCompletion:completion];
249+
}
250+
251+
- (void)popToRootAndSwitchToViewController:(UIViewController *)viewController
252+
withCompletion:(void (^)())completion
253+
{
254+
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeRoot andCompletion:completion];
255+
}
256+
257+
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController
258+
withSlideOutAnimation:(BOOL)slideOutAnimation
259+
andCompletion:(void (^)())completion
260+
{
261+
[self switchToViewController:viewController withSlideOutAnimation:slideOutAnimation popType:PopTypeAll andCompletion:completion];
262+
}
263+
264+
- (void)popAllAndSwitchToViewController:(UIViewController *)viewController
265+
withCompletion:(void (^)())completion
266+
{
267+
[self switchToViewController:viewController withSlideOutAnimation:YES popType:PopTypeAll andCompletion:completion];
268+
}
269+
212270
- (void)closeMenuWithCompletion:(void (^)())completion
213271
{
214272
[self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];

0 commit comments

Comments
 (0)