Skip to content

Commit 411c1c6

Browse files
author
Sean Wolter
committed
Merge pull request #1 from designatednerd/master
Added options for how to show the new main view controller
2 parents 714e9d2 + 79d96ff commit 411c1c6

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

TWTSideMenuViewController/TWTSideMenuViewController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626

2727
@interface TWTSideMenuViewController : UIViewController
2828

29+
typedef NS_ENUM(NSInteger, TWTSideMenuAnimationType) {
30+
TWTSideMenuAnimationTypeSlideOver, //Default - new view controllers slide over the old view controller.
31+
TWTSideMenuAnimationTypeFadeIn //New View controllers fade in over the old view controller.
32+
};
33+
34+
/** The animation type - will default to Slide Over. */
35+
@property (nonatomic, assign) TWTSideMenuAnimationType animationType;
36+
2937
/** Time interval for opening and closing the side menu */
3038
@property (nonatomic, assign) NSTimeInterval animationDuration;
3139

TWTSideMenuViewController/TWTSideMenuViewController.m

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ - (id)initWithMenuViewController:(UIViewController *)menuViewController mainView
6464
- (void)commonInitialization
6565
{
6666
self.animationDuration = kDefaultAnimationDuration;
67+
self.animationType = TWTSideMenuAnimationTypeSlideOver;
6768

6869
[self addViewController:self.menuViewController];
6970
[self addViewController:self.mainViewController];
@@ -293,7 +294,6 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B
293294
animation.duration = kDefaultAnimationDuration;
294295
[overlayView.layer addAnimation:animation forKey:@"opacity"];
295296

296-
CGFloat outgoingStartX = CGRectGetMaxX(outgoingViewController.view.frame);
297297
NSTimeInterval changeTimeInterval = kDefaultSwapAnimationDuration;
298298
NSTimeInterval delayInterval = kDefaultAnimationDelayDuration;
299299
if (!self.open) {
@@ -306,10 +306,35 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B
306306
[self.containerView addSubview:incomingViewController.view];
307307

308308
incomingViewController.view.frame = self.containerView.bounds;
309-
incomingViewController.view.transform = CGAffineTransformTranslate(incomingViewController.view.transform, outgoingStartX, 0.0f);
309+
310+
311+
//Create default animation curve.
312+
UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut;
313+
switch (self.animationType) {
314+
case TWTSideMenuAnimationTypeSlideOver: {
315+
CGFloat outgoingStartX = CGRectGetMaxX(outgoingViewController.view.frame);
316+
317+
incomingViewController.view.transform = CGAffineTransformTranslate(incomingViewController.view.transform, outgoingStartX, 0.0f);
318+
break;
319+
}
320+
case TWTSideMenuAnimationTypeFadeIn:
321+
incomingViewController.view.alpha = .6;
322+
options = UIViewAnimationOptionCurveEaseOut;
323+
324+
break;
325+
}
326+
310327

311328
void (^swapChangeBlock)(void) = ^{
312-
incomingViewController.view.transform = CGAffineTransformIdentity;
329+
switch (self.animationType) {
330+
case TWTSideMenuAnimationTypeSlideOver:
331+
incomingViewController.view.transform = CGAffineTransformIdentity;
332+
break;
333+
case TWTSideMenuAnimationTypeFadeIn:
334+
incomingViewController.view.alpha = 1;
335+
default:
336+
break;
337+
}
313338
};
314339

315340
void (^finishedChangeBlock)(BOOL finished) = ^(BOOL finished) {
@@ -330,7 +355,7 @@ - (void)setMainViewController:(UIViewController *)mainViewController animated:(B
330355

331356
[UIView animateWithDuration:changeTimeInterval
332357
delay:delayInterval
333-
options:UIViewAnimationOptionCurveEaseInOut
358+
options:options
334359
animations:swapChangeBlock
335360
completion:finishedChangeBlock];
336361
} else {

0 commit comments

Comments
 (0)