Skip to content

Commit a759310

Browse files
committed
- Separated all reveal animations from SlideNavigationController
- Allowing a custom animation to be passed to slide menu and used for menu reveal animation
1 parent 373be13 commit a759310

15 files changed

+539
-150
lines changed

SlideMenu.xcodeproj/project.pbxproj

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
15371F141728E3B400A508F4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 15371F121728E3B400A508F4 /* InfoPlist.strings */; };
2525
15371F171728E3B400A508F4 /* SlideMenuTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 15371F161728E3B400A508F4 /* SlideMenuTests.m */; };
2626
15371F281728E44E00A508F4 /* SlideNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15371F271728E44E00A508F4 /* SlideNavigationController.m */; };
27+
15C9AC111895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.m in Sources */ = {isa = PBXBuildFile; fileRef = 15C9AC101895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.m */; };
28+
15C9AC141895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.m in Sources */ = {isa = PBXBuildFile; fileRef = 15C9AC131895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.m */; };
29+
15C9AC171895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.m in Sources */ = {isa = PBXBuildFile; fileRef = 15C9AC161895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.m */; };
30+
15C9AC1A1895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.m in Sources */ = {isa = PBXBuildFile; fileRef = 15C9AC191895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.m */; };
31+
15C9AC1D1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.m in Sources */ = {isa = PBXBuildFile; fileRef = 15C9AC1C1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.m */; };
2732
15CBD67C172A15F900F0C53E /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CBD677172A15F900F0C53E /* HomeViewController.m */; };
2833
15CBD67D172A15F900F0C53E /* MenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CBD679172A15F900F0C53E /* MenuViewController.m */; };
2934
15CBD67E172A15F900F0C53E /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15CBD67B172A15F900F0C53E /* ProfileViewController.m */; };
@@ -68,6 +73,17 @@
6873
15371F161728E3B400A508F4 /* SlideMenuTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SlideMenuTests.m; sourceTree = "<group>"; };
6974
15371F261728E44E00A508F4 /* SlideNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationController.h; sourceTree = "<group>"; };
7075
15371F271728E44E00A508F4 /* SlideNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationController.m; sourceTree = "<group>"; };
76+
15C9AC0F1895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimatorSlide.h; sourceTree = "<group>"; };
77+
15C9AC101895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationContorllerAnimatorSlide.m; sourceTree = "<group>"; };
78+
15C9AC121895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimatorFade.h; sourceTree = "<group>"; };
79+
15C9AC131895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationContorllerAnimatorFade.m; sourceTree = "<group>"; };
80+
15C9AC151895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimatorSlideAndFade.h; sourceTree = "<group>"; };
81+
15C9AC161895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationContorllerAnimatorSlideAndFade.m; sourceTree = "<group>"; };
82+
15C9AC181895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimatorScale.h; sourceTree = "<group>"; };
83+
15C9AC191895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationContorllerAnimatorScale.m; sourceTree = "<group>"; };
84+
15C9AC1B1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimatorScaleAndFade.h; sourceTree = "<group>"; };
85+
15C9AC1C1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideNavigationContorllerAnimatorScaleAndFade.m; sourceTree = "<group>"; };
86+
15C9AC1E1895A832006E6F27 /* SlideNavigationContorllerAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideNavigationContorllerAnimator.h; sourceTree = "<group>"; };
7187
15CBD676172A15F900F0C53E /* HomeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeViewController.h; sourceTree = "<group>"; };
7288
15CBD677172A15F900F0C53E /* HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeViewController.m; sourceTree = "<group>"; };
7389
15CBD678172A15F900F0C53E /* MenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuViewController.h; sourceTree = "<group>"; };
@@ -189,13 +205,32 @@
189205
15371F241728E43600A508F4 /* Source */ = {
190206
isa = PBXGroup;
191207
children = (
208+
15C9AC0E1895A79A006E6F27 /* Animations */,
192209
15CBD681172A209500F0C53E /* Assets */,
193210
15371F261728E44E00A508F4 /* SlideNavigationController.h */,
194211
15371F271728E44E00A508F4 /* SlideNavigationController.m */,
195212
);
196213
path = Source;
197214
sourceTree = "<group>";
198215
};
216+
15C9AC0E1895A79A006E6F27 /* Animations */ = {
217+
isa = PBXGroup;
218+
children = (
219+
15C9AC0F1895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.h */,
220+
15C9AC101895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.m */,
221+
15C9AC121895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.h */,
222+
15C9AC131895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.m */,
223+
15C9AC151895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.h */,
224+
15C9AC161895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.m */,
225+
15C9AC181895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.h */,
226+
15C9AC191895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.m */,
227+
15C9AC1B1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.h */,
228+
15C9AC1C1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.m */,
229+
15C9AC1E1895A832006E6F27 /* SlideNavigationContorllerAnimator.h */,
230+
);
231+
path = Animations;
232+
sourceTree = "<group>";
233+
};
199234
15CBD675172A15F900F0C53E /* Helper Classes */ = {
200235
isa = PBXGroup;
201236
children = (
@@ -335,12 +370,17 @@
335370
isa = PBXSourcesBuildPhase;
336371
buildActionMask = 2147483647;
337372
files = (
373+
15C9AC1D1895A81D006E6F27 /* SlideNavigationContorllerAnimatorScaleAndFade.m in Sources */,
374+
15C9AC171895A7E7006E6F27 /* SlideNavigationContorllerAnimatorSlideAndFade.m in Sources */,
338375
15371EEF1728E3B400A508F4 /* main.m in Sources */,
339376
15371EF31728E3B400A508F4 /* AppDelegate.m in Sources */,
377+
15C9AC141895A7D7006E6F27 /* SlideNavigationContorllerAnimatorFade.m in Sources */,
340378
15371F281728E44E00A508F4 /* SlideNavigationController.m in Sources */,
379+
15C9AC111895A7BF006E6F27 /* SlideNavigationContorllerAnimatorSlide.m in Sources */,
341380
15CBD67C172A15F900F0C53E /* HomeViewController.m in Sources */,
342381
997929E2187336AA00716C77 /* FriendsViewController.m in Sources */,
343382
15CBD67D172A15F900F0C53E /* MenuViewController.m in Sources */,
383+
15C9AC1A1895A80E006E6F27 /* SlideNavigationContorllerAnimatorScale.m in Sources */,
344384
15CBD67E172A15F900F0C53E /* ProfileViewController.m in Sources */,
345385
15CBD689172A22B700F0C53E /* ProfileDetailViewController.m in Sources */,
346386
);

SlideMenu/Helper Classes/MenuViewController.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
//
88

99
#import "MenuViewController.h"
10+
#import "SlideNavigationContorllerAnimatorFade.h"
11+
#import "SlideNavigationContorllerAnimatorSlide.h"
12+
#import "SlideNavigationContorllerAnimatorScale.h"
13+
#import "SlideNavigationContorllerAnimatorScaleAndFade.h"
14+
#import "SlideNavigationContorllerAnimatorSlideAndFade.h"
1015

1116
@implementation MenuViewController
1217
@synthesize cellIdentifier;
@@ -74,7 +79,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
7479
bundle: nil];
7580

7681
UIViewController *vc ;
77-
MenuRevealAnimation revealAnimation = MenuRevealAnimationNone;
82+
id <SlideNavigationContorllerAnimator> revealAnimator;
7883

7984
switch (indexPath.row)
8085
{
@@ -96,27 +101,27 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
96101
break;
97102

98103
case 4:
99-
revealAnimation = MenuRevealAnimationNone;
104+
revealAnimator = nil;
100105
break;
101106

102107
case 5:
103-
revealAnimation = MenuRevealAnimationSlide;
108+
revealAnimator = [[SlideNavigationContorllerAnimatorSlide alloc] init];
104109
break;
105110

106111
case 6:
107-
revealAnimation = MenuRevealAnimationFade;
112+
revealAnimator = [[SlideNavigationContorllerAnimatorFade alloc] init];
108113
break;
109114

110115
case 7:
111-
revealAnimation = MenuRevealAnimationSlideAndFade;
116+
revealAnimator = [[SlideNavigationContorllerAnimatorSlideAndFade alloc] init];
112117
break;
113118

114119
case 8:
115-
revealAnimation = MenuRevealAnimationScale;
120+
revealAnimator = [[SlideNavigationContorllerAnimatorScale alloc] init];
116121
break;
117122

118123
case 9:
119-
revealAnimation = MenuRevealAnimationScaleAndFade;
124+
revealAnimator = [[SlideNavigationContorllerAnimatorScaleAndFade alloc] init];
120125
break;
121126

122127
default:
@@ -127,7 +132,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
127132
[[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil];
128133
else
129134
[[SlideNavigationController sharedInstance] closeMenuWithCompletion:^{
130-
[SlideNavigationController sharedInstance].menuRevealAnimation = revealAnimation;
135+
[SlideNavigationController sharedInstance].menuRevealAnimator = revealAnimator;
131136
}];
132137
}
133138

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// SlideNavigationContorllerAnimation.h
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "SlideNavigationController.h"
11+
12+
@protocol SlideNavigationContorllerAnimator <NSObject>
13+
14+
// Initial state of the view before animation starts
15+
// This gets called right before the menu is about to reveal
16+
- (void)prepareMenuForAnimation:(Menu)menu;
17+
18+
// Animate the view based on the progress (progress is between 0 and 1)
19+
- (void)animateMenu:(Menu)menu withProgress:(CGFloat)progress;
20+
21+
// Gets called ff for any the instance of animator is being change
22+
// You should make any cleanup that is needed
23+
- (void)clear;
24+
25+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// SlideNavigationContorllerAnimationFade.h
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "SlideNavigationContorllerAnimator.h"
11+
12+
@interface SlideNavigationContorllerAnimatorFade : NSObject <SlideNavigationContorllerAnimator>
13+
14+
@property (nonatomic, assign) CGFloat maximumFadeAlpha;
15+
@property (nonatomic, strong) UIColor *fadeColor;
16+
17+
- (id)initWithMaximumFadeAlpha:(CGFloat)maximumFadeAlpha andFadeColor:(UIColor *)fadeColor;
18+
19+
@end
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// SlideNavigationContorllerAnimationFade.m
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import "SlideNavigationContorllerAnimatorFade.h"
10+
11+
@interface SlideNavigationContorllerAnimatorFade()
12+
@property (nonatomic, strong) UIView *fadeAnimationView;
13+
@end
14+
15+
@implementation SlideNavigationContorllerAnimatorFade
16+
17+
#pragma mark - Initialization -
18+
19+
- (id)init
20+
{
21+
if (self = [self initWithMaximumFadeAlpha:.8 andFadeColor:[UIColor blackColor]])
22+
{
23+
}
24+
25+
return self;
26+
}
27+
28+
- (id)initWithMaximumFadeAlpha:(CGFloat)maximumFadeAlpha andFadeColor:(UIColor *)fadeColor
29+
{
30+
if (self = [super init])
31+
{
32+
self.maximumFadeAlpha = maximumFadeAlpha;
33+
self.fadeColor = fadeColor;
34+
35+
self.fadeAnimationView = [[UIView alloc] init];
36+
self.fadeAnimationView.backgroundColor = self.fadeColor;
37+
}
38+
39+
return self;
40+
}
41+
42+
#pragma mark - SlideNavigationContorllerAnimation Methods -
43+
44+
- (void)prepareMenuForAnimation:(Menu)menu
45+
{
46+
UIViewController *menuViewController = (menu == MenuLeft)
47+
? [SlideNavigationController sharedInstance].leftMenu
48+
: [SlideNavigationController sharedInstance].rightMenu;
49+
50+
self.fadeAnimationView.alpha = self.maximumFadeAlpha;
51+
self.fadeAnimationView.frame = menuViewController.view.bounds;
52+
}
53+
54+
- (void)animateMenu:(Menu)menu withProgress:(CGFloat)progress
55+
{
56+
UIViewController *menuViewController = (menu == MenuLeft)
57+
? [SlideNavigationController sharedInstance].leftMenu
58+
: [SlideNavigationController sharedInstance].rightMenu;
59+
60+
self.fadeAnimationView.frame = menuViewController.view.bounds;
61+
[menuViewController.view addSubview:self.fadeAnimationView];
62+
self.fadeAnimationView.alpha = self.maximumFadeAlpha - (self.maximumFadeAlpha *progress);
63+
}
64+
65+
- (void)clear
66+
{
67+
[self.fadeAnimationView removeFromSuperview];
68+
}
69+
70+
@end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// SlideNavigationContorllerAnimationScale.h
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "SlideNavigationContorllerAnimator.h"
11+
12+
@interface SlideNavigationContorllerAnimatorScale : NSObject <SlideNavigationContorllerAnimator>
13+
14+
@property (nonatomic, assign) CGFloat minimumScale;
15+
16+
- (id)initWithMinimumScale:(CGFloat)minimumScale;
17+
18+
@end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// SlideNavigationContorllerAnimationScale.m
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import "SlideNavigationContorllerAnimatorScale.h"
10+
11+
@implementation SlideNavigationContorllerAnimatorScale
12+
13+
#pragma mark - Initialization -
14+
15+
- (id)init
16+
{
17+
if (self = [self initWithMinimumScale:.8])
18+
{
19+
}
20+
21+
return self;
22+
}
23+
24+
- (id)initWithMinimumScale:(CGFloat)minimumScale
25+
{
26+
if (self = [super init])
27+
{
28+
self.minimumScale = minimumScale;
29+
}
30+
31+
return self;
32+
}
33+
34+
#pragma mark - SlideNavigationContorllerAnimation Methods -
35+
36+
- (void)prepareMenuForAnimation:(Menu)menu
37+
{
38+
UIViewController *menuViewController = (menu == MenuLeft)
39+
? [SlideNavigationController sharedInstance].leftMenu
40+
: [SlideNavigationController sharedInstance].rightMenu;
41+
42+
menuViewController.view.transform = CGAffineTransformScale([SlideNavigationController sharedInstance].view.transform, self.minimumScale, self.minimumScale);
43+
}
44+
45+
- (void)animateMenu:(Menu)menu withProgress:(CGFloat)progress
46+
{
47+
UIViewController *menuViewController = (menu == MenuLeft)
48+
? [SlideNavigationController sharedInstance].leftMenu
49+
: [SlideNavigationController sharedInstance].rightMenu;
50+
51+
CGFloat scale = MIN(1, (1-self.minimumScale) *progress + self.minimumScale);
52+
menuViewController.view.transform = CGAffineTransformScale([SlideNavigationController sharedInstance].view.transform, scale, scale);
53+
}
54+
55+
- (void)clear
56+
{
57+
[SlideNavigationController sharedInstance].leftMenu.view.transform = CGAffineTransformScale([SlideNavigationController sharedInstance].view.transform, 1, 1);
58+
[SlideNavigationController sharedInstance].rightMenu.view.transform = CGAffineTransformScale([SlideNavigationController sharedInstance].view.transform, 1, 1);
59+
}
60+
61+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// SlideNavigationContorllerAnimationScaleAndFade.h
3+
// SlideMenu
4+
//
5+
// Created by Aryan Gh on 1/26/14.
6+
// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "SlideNavigationContorllerAnimator.h"
11+
12+
@interface SlideNavigationContorllerAnimatorScaleAndFade : NSObject <SlideNavigationContorllerAnimator>
13+
14+
15+
@end

0 commit comments

Comments
 (0)