Skip to content

Commit

Permalink
Merge pull request #1 from designatednerd/master
Browse files Browse the repository at this point in the history
Added options for how to show the new main view controller
  • Loading branch information
Sean Wolter committed Oct 31, 2013
2 parents 714e9d2 + 79d96ff commit 411c1c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions TWTSideMenuViewController/TWTSideMenuViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 29 additions & 4 deletions TWTSideMenuViewController/TWTSideMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -330,7 +355,7 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B

[UIView animateWithDuration:changeTimeInterval
delay:delayInterval
options:UIViewAnimationOptionCurveEaseInOut
options:options
animations:swapChangeBlock
completion:finishedChangeBlock];
} else {
Expand Down

0 comments on commit 411c1c6

Please sign in to comment.