Skip to content

Commit eca1362

Browse files
committed
Added Notifications for closing/opening/revealing menu #32
1 parent 3513ce0 commit eca1362

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

SlideMenu.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
15371EF81728E3B400A508F4 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
7070
15371EFB1728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPhone.storyboard; sourceTree = "<group>"; };
7171
15371EFE1728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPad.storyboard; sourceTree = "<group>"; };
72-
15371F081728E3B400A508F4 /* SlideMenuTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SlideMenuTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
72+
15371F081728E3B400A508F4 /* SlideMenuTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SlideMenuTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7373
15371F111728E3B400A508F4 /* SlideMenuTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SlideMenuTests-Info.plist"; sourceTree = "<group>"; };
7474
15371F131728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
7575
15371F151728E3B400A508F4 /* SlideMenuTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlideMenuTests.h; sourceTree = "<group>"; };
@@ -146,7 +146,7 @@
146146
isa = PBXGroup;
147147
children = (
148148
15371EDE1728E3B400A508F4 /* SlideMenu.app */,
149-
15371F081728E3B400A508F4 /* SlideMenuTests.octest */,
149+
15371F081728E3B400A508F4 /* SlideMenuTests.xctest */,
150150
);
151151
name = Products;
152152
sourceTree = "<group>";
@@ -314,7 +314,7 @@
314314
);
315315
name = SlideMenuTests;
316316
productName = SlideMenuTests;
317-
productReference = 15371F081728E3B400A508F4 /* SlideMenuTests.octest */;
317+
productReference = 15371F081728E3B400A508F4 /* SlideMenuTests.xctest */;
318318
productType = "com.apple.product-type.bundle.unit-test";
319319
};
320320
/* End PBXNativeTarget section */

SlideMenu/AppDelegate.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3030
[button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];
3131
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
3232
[SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;
33+
34+
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) {
35+
NSString *menu = note.userInfo[@"menu"];
36+
NSLog(@"Closed %@", menu);
37+
}];
38+
39+
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) {
40+
NSString *menu = note.userInfo[@"menu"];
41+
NSLog(@"Opened %@", menu);
42+
}];
43+
44+
[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) {
45+
NSString *menu = note.userInfo[@"menu"];
46+
NSLog(@"Revealed %@", menu);
47+
}];
3348

3449

3550
// Override point for customization after application launch.

SlideMenu/Source/SlideNavigationController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ typedef enum{
4242
@protocol SlideNavigationContorllerAnimator;
4343
@interface SlideNavigationController : UINavigationController <UINavigationControllerDelegate>
4444

45+
extern NSString * const SlideNavigationControllerDidOpen;
46+
extern NSString *const SlideNavigationControllerDidClose;
47+
extern NSString *const SlideNavigationControllerDidReveal;
48+
4549
@property (nonatomic, assign) BOOL avoidSwitchingToSameClassViewController;
4650
@property (nonatomic, assign) BOOL enableSwipeGesture;
4751
@property (nonatomic, assign) BOOL enableShadow;

SlideMenu/Source/SlideNavigationController.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ @interface SlideNavigationController() <UIGestureRecognizerDelegate>
4242

4343
@implementation SlideNavigationController
4444

45+
NSString * const SlideNavigationControllerDidOpen = @"SlideNavigationControllerDidOpen";
46+
NSString * const SlideNavigationControllerDidClose = @"SlideNavigationControllerDidClose";
47+
NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal";
48+
4549
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
4650
#define MENU_SLIDE_ANIMATION_DURATION .3
4751
#define MENU_QUICK_SLIDE_ANIMATION_DURATION .18
@@ -51,6 +55,9 @@ @implementation SlideNavigationController
5155
#define MENU_DEFAULT_SLIDE_OFFSET 60
5256
#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
5357
#define STATUS_BAR_HEIGHT 20
58+
#define NOTIFICATION_USER_INFO_MENU_LEFT @"left"
59+
#define NOTIFICATION_USER_INFO_MENU_RIGHT @"right"
60+
#define NOTIFICATION_USER_INFO_MENU @"menu"
5461

5562
static SlideNavigationController *singletonInstance;
5663

@@ -462,12 +469,16 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
462469
completion:^(BOOL finished) {
463470
if (completion)
464471
completion();
472+
473+
[self postNotificationWithName:SlideNavigationControllerDidOpen forMenu:menu];
465474
}];
466475
}
467476

468477
- (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completion
469478
{
470479
[self enableTapGestureToCloseMenu:NO];
480+
481+
Menu menu = (self.horizontalLocation > 0) ? MenuLeft : MenuRight;
471482

472483
[UIView animateWithDuration:duration
473484
delay:0
@@ -480,6 +491,8 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
480491
completion:^(BOOL finished) {
481492
if (completion)
482493
completion();
494+
495+
[self postNotificationWithName:SlideNavigationControllerDidClose forMenu:menu];
483496
}];
484497
}
485498

@@ -488,6 +501,10 @@ - (void)moveHorizontallyToLocation:(CGFloat)location
488501
CGRect rect = self.view.frame;
489502
UIInterfaceOrientation orientation = self.interfaceOrientation;
490503
Menu menu = (self.horizontalLocation >= 0 && location >= 0) ? MenuLeft : MenuRight;
504+
505+
if ((location > 0 && self.horizontalLocation <= 0) || (location < 0 && self.horizontalLocation >= 0)) {
506+
[self postNotificationWithName:SlideNavigationControllerDidReveal forMenu:(location > 0) ? MenuLeft : MenuRight];
507+
}
491508

492509
if (UIInterfaceOrientationIsLandscape(orientation))
493510
{
@@ -596,6 +613,13 @@ - (CGFloat)horizontalSize
596613
}
597614
}
598615

616+
- (void)postNotificationWithName:(NSString *)name forMenu:(Menu)menu
617+
{
618+
NSString *menuString = (menu == MenuLeft) ? NOTIFICATION_USER_INFO_MENU_LEFT : NOTIFICATION_USER_INFO_MENU_RIGHT;
619+
NSDictionary *userInfo = @{ NOTIFICATION_USER_INFO_MENU : menuString };
620+
[[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:userInfo];
621+
}
622+
599623
#pragma mark - UINavigationControllerDelegate Methods -
600624

601625
- (void)navigationController:(UINavigationController *)navigationController
@@ -624,7 +648,6 @@ - (void)leftMenuSelected:(id)sender
624648
[self closeMenuWithCompletion:nil];
625649
else
626650
[self openMenu:MenuLeft withCompletion:nil];
627-
628651
}
629652

630653
- (void)righttMenuSelected:(id)sender
@@ -670,6 +693,9 @@ - (void)panDetected:(UIPanGestureRecognizer *)aPanRecognizer
670693
else
671694
currentMenu = (translation.x > 0) ? MenuLeft : MenuRight;
672695

696+
if (![self shouldDisplayMenu:currentMenu forViewController:self.topViewController])
697+
return;
698+
673699
[self prepareMenuForReveal:currentMenu];
674700

675701
if (aPanRecognizer.state == UIGestureRecognizerStateBegan)

iOS-Slide-Menu.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Pod::Spec.new do |s|
22
s.name = 'iOS-Slide-Menu'
3-
s.version = '1.4.1'
3+
s.version = '1.4.2'
44
s.summary = 'A Slide Menu for iOS'
55
s.homepage = 'https://github.com/aryaxt/iOS-Slide-Menu'
66
s.license = {
77
:type => 'MIT',
88
:file => 'License.txt'
99
}
1010
s.author = {'Aryan Gh' => 'https://github.com/aryaxt/iOS-Slide-Menu'}
11-
s.source = {:git => 'https://github.com/aryaxt/iOS-Slide-Menu.git', :tag => '1.4.1'}
11+
s.source = {:git => 'https://github.com/aryaxt/iOS-Slide-Menu.git', :tag => '1.4.2'}
1212
s.platform = :ios, '6.0'
1313
s.source_files = 'SlideMenu/Source/*.{h,m}', 'SlideMenu/Source/Animations/*.{h,m}', 'SlideMenu/Source/Assets/*.{png}'
1414
s.resources = ['SlideMenu/Source/Assets/**/*']

0 commit comments

Comments
 (0)