From 79d96ff25814364cae25c2a6189c7ff8d7169750 Mon Sep 17 00:00:00 2001 From: Ellen Shapiro Date: Thu, 31 Oct 2013 10:45:02 -0500 Subject: [PATCH] Added options for how to show the new main view controller --- .../TWTSideMenuViewController.h | 8 +++++ .../TWTSideMenuViewController.m | 33 ++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/TWTSideMenuViewController/TWTSideMenuViewController.h b/TWTSideMenuViewController/TWTSideMenuViewController.h index 59573b0..4858254 100644 --- a/TWTSideMenuViewController/TWTSideMenuViewController.h +++ b/TWTSideMenuViewController/TWTSideMenuViewController.h @@ -26,6 +26,14 @@ @interface TWTSideMenuViewController : UIViewController +typedef NS_ENUM(NSInteger, TWTSideMenuAnimationType) { + TWTSideMenuAnimationTypeSlideOver, //Default - new view controllers slide over the old view controller. + TWTSideMenuAnimationTypeFadeIn //New View controllers fade in over the old view controller. +}; + +/** The animation type - will default to Slide Over. */ +@property (nonatomic, assign) TWTSideMenuAnimationType animationType; + /** Time interval for opening and closing the side menu */ @property (nonatomic, assign) NSTimeInterval animationDuration; diff --git a/TWTSideMenuViewController/TWTSideMenuViewController.m b/TWTSideMenuViewController/TWTSideMenuViewController.m index f6d3a5e..756c340 100644 --- a/TWTSideMenuViewController/TWTSideMenuViewController.m +++ b/TWTSideMenuViewController/TWTSideMenuViewController.m @@ -64,6 +64,7 @@ - (id)initWithMenuViewController:(UIViewController *)menuViewController mainView - (void)commonInitialization { self.animationDuration = kDefaultAnimationDuration; + self.animationType = TWTSideMenuAnimationTypeSlideOver; [self addViewController:self.menuViewController]; [self addViewController:self.mainViewController]; @@ -293,7 +294,6 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B animation.duration = kDefaultAnimationDuration; [overlayView.layer addAnimation:animation forKey:@"opacity"]; - CGFloat outgoingStartX = CGRectGetMaxX(outgoingViewController.view.frame); NSTimeInterval changeTimeInterval = kDefaultSwapAnimationDuration; NSTimeInterval delayInterval = kDefaultAnimationDelayDuration; if (!self.open) { @@ -306,10 +306,35 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B [self.containerView addSubview:incomingViewController.view]; incomingViewController.view.frame = self.containerView.bounds; - incomingViewController.view.transform = CGAffineTransformTranslate(incomingViewController.view.transform, outgoingStartX, 0.0f); + + + //Create default animation curve. + UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut; + switch (self.animationType) { + case TWTSideMenuAnimationTypeSlideOver: { + CGFloat outgoingStartX = CGRectGetMaxX(outgoingViewController.view.frame); + + incomingViewController.view.transform = CGAffineTransformTranslate(incomingViewController.view.transform, outgoingStartX, 0.0f); + break; + } + case TWTSideMenuAnimationTypeFadeIn: + incomingViewController.view.alpha = .6; + options = UIViewAnimationOptionCurveEaseOut; + + break; + } + void (^swapChangeBlock)(void) = ^{ - incomingViewController.view.transform = CGAffineTransformIdentity; + switch (self.animationType) { + case TWTSideMenuAnimationTypeSlideOver: + incomingViewController.view.transform = CGAffineTransformIdentity; + break; + case TWTSideMenuAnimationTypeFadeIn: + incomingViewController.view.alpha = 1; + default: + break; + } }; void (^finishedChangeBlock)(BOOL finished) = ^(BOOL finished) { @@ -330,7 +355,7 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B [UIView animateWithDuration:changeTimeInterval delay:delayInterval - options:UIViewAnimationOptionCurveEaseInOut + options:options animations:swapChangeBlock completion:finishedChangeBlock]; } else {