Skip to content

Commit 4c66f6c

Browse files
committed
Allow configuring animation duration/option
1 parent 43f62e7 commit 4c66f6c

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

SlideMenu/AppDelegate.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2323

2424
[SlideNavigationController sharedInstance].rightMenu = rightMenu;
2525
[SlideNavigationController sharedInstance].leftMenu = leftMenu;
26+
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;
2627

2728
// Creating a custom bar button for right menu
2829
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

SlideMenu/Helper Classes/RightMenuViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,46 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
8080
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
8181
{
8282
id <SlideNavigationContorllerAnimator> revealAnimator;
83+
CGFloat animationDuration = 0;
8384

8485
switch (indexPath.row)
8586
{
8687
case 0:
8788
revealAnimator = nil;
89+
animationDuration = .19;
8890
break;
8991

9092
case 1:
9193
revealAnimator = [[SlideNavigationContorllerAnimatorSlide alloc] init];
94+
animationDuration = .19;
9295
break;
9396

9497
case 2:
9598
revealAnimator = [[SlideNavigationContorllerAnimatorFade alloc] init];
99+
animationDuration = .18;
96100
break;
97101

98102
case 3:
99103
revealAnimator = [[SlideNavigationContorllerAnimatorSlideAndFade alloc] initWithMaximumFadeAlpha:.8 fadeColor:[UIColor blackColor] andSlideMovement:100];
104+
animationDuration = .19;
100105
break;
101106

102107
case 4:
103108
revealAnimator = [[SlideNavigationContorllerAnimatorScale alloc] init];
109+
animationDuration = .22;
104110
break;
105111

106112
case 5:
107113
revealAnimator = [[SlideNavigationContorllerAnimatorScaleAndFade alloc] initWithMaximumFadeAlpha:.6 fadeColor:[UIColor blackColor] andMinimumScale:.8];
114+
animationDuration = .22;
108115
break;
109116

110117
default:
111118
return;
112119
}
113120

114121
[[SlideNavigationController sharedInstance] closeMenuWithCompletion:^{
122+
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = animationDuration;
115123
[SlideNavigationController sharedInstance].menuRevealAnimator = revealAnimator;
116124
}];
117125
}

SlideMenu/Source/SlideNavigationController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extern NSString *const SlideNavigationControllerDidReveal;
5858
@property (nonatomic, assign) CGFloat portraitSlideOffset;
5959
@property (nonatomic, assign) CGFloat landscapeSlideOffset;
6060
@property (nonatomic, assign) CGFloat panGestureSideOffset;
61+
@property (nonatomic, assign) CGFloat menuRevealAnimationDuration;
62+
@property (nonatomic, assign) UIViewAnimationOptions menuRevealAnimationOption;
6163
@property (nonatomic, strong) id <SlideNavigationContorllerAnimator> menuRevealAnimator;
6264

6365
+ (SlideNavigationController *)sharedInstance;

SlideMenu/Source/SlideNavigationController.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ @implementation SlideNavigationController
4848
NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal";
4949

5050
#define MENU_SLIDE_ANIMATION_DURATION .3
51+
#define MENU_SLIDE_ANIMATION_OPTION UIViewAnimationOptionCurveEaseOut
5152
#define MENU_QUICK_SLIDE_ANIMATION_DURATION .18
5253
#define MENU_IMAGE @"menu-button"
5354
#define MENU_SHADOW_RADIUS 10
@@ -108,6 +109,8 @@ - (void)setup
108109

109110
singletonInstance = self;
110111

112+
self.menuRevealAnimationDuration = MENU_SLIDE_ANIMATION_DURATION;
113+
self.menuRevealAnimationOption = MENU_SLIDE_ANIMATION_OPTION;
111114
self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
112115
self.portraitSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
113116
self.panGestureSideOffset = 0;
@@ -230,9 +233,9 @@ - (void)switchToViewController:(UIViewController *)viewController
230233
{
231234
if (slideOutAnimation)
232235
{
233-
[UIView animateWithDuration:(slideOutAnimation) ? MENU_SLIDE_ANIMATION_DURATION : 0
236+
[UIView animateWithDuration:(slideOutAnimation) ? self.menuRevealAnimationDuration : 0
234237
delay:0
235-
options:UIViewAnimationOptionCurveEaseOut
238+
options:self.menuRevealAnimationOption
236239
animations:^{
237240
CGFloat width = self.horizontalSize;
238241
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
@@ -285,12 +288,12 @@ - (void)popAllAndSwitchToViewController:(UIViewController *)viewController
285288

286289
- (void)closeMenuWithCompletion:(void (^)())completion
287290
{
288-
[self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];
291+
[self closeMenuWithDuration:self.menuRevealAnimationDuration andCompletion:completion];
289292
}
290293

291294
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion
292295
{
293-
[self openMenu:menu withDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];
296+
[self openMenu:menu withDuration:self.menuRevealAnimationDuration andCompletion:completion];
294297
}
295298

296299
- (void)toggleLeftMenu
@@ -465,7 +468,7 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
465468

466469
[UIView animateWithDuration:duration
467470
delay:0
468-
options:UIViewAnimationOptionCurveEaseOut
471+
options:self.menuRevealAnimationOption
469472
animations:^{
470473
CGRect rect = self.view.frame;
471474
CGFloat width = self.horizontalSize;
@@ -488,7 +491,7 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
488491

489492
[UIView animateWithDuration:duration
490493
delay:0
491-
options:UIViewAnimationOptionCurveEaseOut
494+
options:self.menuRevealAnimationOption
492495
animations:^{
493496
CGRect rect = self.view.frame;
494497
rect.origin.x = 0;

0 commit comments

Comments
 (0)