Allow configuring animation duration/option

This commit is contained in:
Aryan 2014-11-28 15:34:55 -08:00
parent 43f62e7321
commit 4c66f6c25c
4 changed files with 20 additions and 6 deletions

View File

@ -23,6 +23,7 @@
[SlideNavigationController sharedInstance].rightMenu = rightMenu;
[SlideNavigationController sharedInstance].leftMenu = leftMenu;
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;
// Creating a custom bar button for right menu
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

View File

@ -80,31 +80,38 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
id <SlideNavigationContorllerAnimator> revealAnimator;
CGFloat animationDuration = 0;
switch (indexPath.row)
{
case 0:
revealAnimator = nil;
animationDuration = .19;
break;
case 1:
revealAnimator = [[SlideNavigationContorllerAnimatorSlide alloc] init];
animationDuration = .19;
break;
case 2:
revealAnimator = [[SlideNavigationContorllerAnimatorFade alloc] init];
animationDuration = .18;
break;
case 3:
revealAnimator = [[SlideNavigationContorllerAnimatorSlideAndFade alloc] initWithMaximumFadeAlpha:.8 fadeColor:[UIColor blackColor] andSlideMovement:100];
animationDuration = .19;
break;
case 4:
revealAnimator = [[SlideNavigationContorllerAnimatorScale alloc] init];
animationDuration = .22;
break;
case 5:
revealAnimator = [[SlideNavigationContorllerAnimatorScaleAndFade alloc] initWithMaximumFadeAlpha:.6 fadeColor:[UIColor blackColor] andMinimumScale:.8];
animationDuration = .22;
break;
default:
@ -112,6 +119,7 @@
}
[[SlideNavigationController sharedInstance] closeMenuWithCompletion:^{
[SlideNavigationController sharedInstance].menuRevealAnimationDuration = animationDuration;
[SlideNavigationController sharedInstance].menuRevealAnimator = revealAnimator;
}];
}

View File

@ -58,6 +58,8 @@ extern NSString *const SlideNavigationControllerDidReveal;
@property (nonatomic, assign) CGFloat portraitSlideOffset;
@property (nonatomic, assign) CGFloat landscapeSlideOffset;
@property (nonatomic, assign) CGFloat panGestureSideOffset;
@property (nonatomic, assign) CGFloat menuRevealAnimationDuration;
@property (nonatomic, assign) UIViewAnimationOptions menuRevealAnimationOption;
@property (nonatomic, strong) id <SlideNavigationContorllerAnimator> menuRevealAnimator;
+ (SlideNavigationController *)sharedInstance;

View File

@ -48,6 +48,7 @@ NSString * const SlideNavigationControllerDidClose = @"SlideNavigationController
NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal";
#define MENU_SLIDE_ANIMATION_DURATION .3
#define MENU_SLIDE_ANIMATION_OPTION UIViewAnimationOptionCurveEaseOut
#define MENU_QUICK_SLIDE_ANIMATION_DURATION .18
#define MENU_IMAGE @"menu-button"
#define MENU_SHADOW_RADIUS 10
@ -108,6 +109,8 @@ static SlideNavigationController *singletonInstance;
singletonInstance = self;
self.menuRevealAnimationDuration = MENU_SLIDE_ANIMATION_DURATION;
self.menuRevealAnimationOption = MENU_SLIDE_ANIMATION_OPTION;
self.landscapeSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
self.portraitSlideOffset = MENU_DEFAULT_SLIDE_OFFSET;
self.panGestureSideOffset = 0;
@ -230,9 +233,9 @@ static SlideNavigationController *singletonInstance;
{
if (slideOutAnimation)
{
[UIView animateWithDuration:(slideOutAnimation) ? MENU_SLIDE_ANIMATION_DURATION : 0
[UIView animateWithDuration:(slideOutAnimation) ? self.menuRevealAnimationDuration : 0
delay:0
options:UIViewAnimationOptionCurveEaseOut
options:self.menuRevealAnimationOption
animations:^{
CGFloat width = self.horizontalSize;
CGFloat moveLocation = (self.horizontalLocation> 0) ? width : -1*width;
@ -285,12 +288,12 @@ static SlideNavigationController *singletonInstance;
- (void)closeMenuWithCompletion:(void (^)())completion
{
[self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];
[self closeMenuWithDuration:self.menuRevealAnimationDuration andCompletion:completion];
}
- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion
{
[self openMenu:menu withDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];
[self openMenu:menu withDuration:self.menuRevealAnimationDuration andCompletion:completion];
}
- (void)toggleLeftMenu
@ -465,7 +468,7 @@ static SlideNavigationController *singletonInstance;
[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionCurveEaseOut
options:self.menuRevealAnimationOption
animations:^{
CGRect rect = self.view.frame;
CGFloat width = self.horizontalSize;
@ -488,7 +491,7 @@ static SlideNavigationController *singletonInstance;
[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionCurveEaseOut
options:self.menuRevealAnimationOption
animations:^{
CGRect rect = self.view.frame;
rect.origin.x = 0;