Skip to content

Commit

Permalink
Merge pull request #73 from aryaxt/Develop
Browse files Browse the repository at this point in the history
Posting Notifications for menu state open/close/reveal
  • Loading branch information
aryaxt committed Sep 6, 2014
2 parents da97bae + eca1362 commit 8137873
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
17 changes: 7 additions & 10 deletions SlideMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
15371EF91728E3B400A508F4 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 15371EF81728E3B400A508F4 /* [email protected] */; };
15371EFC1728E3B400A508F4 /* MainStoryboard_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 15371EFA1728E3B400A508F4 /* MainStoryboard_iPhone.storyboard */; };
15371EFF1728E3B400A508F4 /* MainStoryboard_iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 15371EFD1728E3B400A508F4 /* MainStoryboard_iPad.storyboard */; };
15371F0A1728E3B400A508F4 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15371F091728E3B400A508F4 /* SenTestingKit.framework */; };
15371F0B1728E3B400A508F4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15371EE21728E3B400A508F4 /* UIKit.framework */; };
15371F0C1728E3B400A508F4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15371EE41728E3B400A508F4 /* Foundation.framework */; };
15371F141728E3B400A508F4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 15371F121728E3B400A508F4 /* InfoPlist.strings */; };
Expand Down Expand Up @@ -70,8 +69,7 @@
15371EF81728E3B400A508F4 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
15371EFB1728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPhone.storyboard; sourceTree = "<group>"; };
15371EFE1728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard_iPad.storyboard; sourceTree = "<group>"; };
15371F081728E3B400A508F4 /* SlideMenuTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SlideMenuTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
15371F091728E3B400A508F4 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
15371F081728E3B400A508F4 /* SlideMenuTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SlideMenuTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
15371F111728E3B400A508F4 /* SlideMenuTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SlideMenuTests-Info.plist"; sourceTree = "<group>"; };
15371F131728E3B400A508F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
15371F151728E3B400A508F4 /* SlideMenuTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlideMenuTests.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -126,7 +124,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
15371F0A1728E3B400A508F4 /* SenTestingKit.framework in Frameworks */,
15371F0B1728E3B400A508F4 /* UIKit.framework in Frameworks */,
15371F0C1728E3B400A508F4 /* Foundation.framework in Frameworks */,
);
Expand All @@ -149,7 +146,7 @@
isa = PBXGroup;
children = (
15371EDE1728E3B400A508F4 /* SlideMenu.app */,
15371F081728E3B400A508F4 /* SlideMenuTests.octest */,
15371F081728E3B400A508F4 /* SlideMenuTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -161,7 +158,6 @@
15371EE21728E3B400A508F4 /* UIKit.framework */,
15371EE41728E3B400A508F4 /* Foundation.framework */,
15371EE61728E3B400A508F4 /* CoreGraphics.framework */,
15371F091728E3B400A508F4 /* SenTestingKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -318,15 +314,16 @@
);
name = SlideMenuTests;
productName = SlideMenuTests;
productReference = 15371F081728E3B400A508F4 /* SlideMenuTests.octest */;
productType = "com.apple.product-type.bundle";
productReference = 15371F081728E3B400A508F4 /* SlideMenuTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
15371ED51728E3B400A508F4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastTestingUpgradeCheck = 0600;
LastUpgradeCheck = 0500;
ORGANIZATIONNAME = "Aryan Ghassemi";
};
Expand Down Expand Up @@ -551,13 +548,13 @@
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SlideMenu/SlideMenu-Prefix.pch";
INFOPLIST_FILE = "SlideMenuTests/SlideMenuTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Debug;
};
Expand All @@ -568,13 +565,13 @@
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SlideMenu/SlideMenu-Prefix.pch";
INFOPLIST_FILE = "SlideMenuTests/SlideMenuTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Release;
};
Expand Down
15 changes: 15 additions & 0 deletions SlideMenu/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Closed %@", menu);
}];

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Opened %@", menu);
}];

[[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) {
NSString *menu = note.userInfo[@"menu"];
NSLog(@"Revealed %@", menu);
}];


// Override point for customization after application launch.
Expand Down
2 changes: 1 addition & 1 deletion SlideMenu/Helper Classes/FriendsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendCell"];
cell.textLabel.text = [NSString stringWithFormat:@"Friend %d", indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"Friend %ld", (long)indexPath.row];
return cell;
}

Expand Down
4 changes: 4 additions & 0 deletions SlideMenu/Source/SlideNavigationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ typedef enum{
@protocol SlideNavigationContorllerAnimator;
@interface SlideNavigationController : UINavigationController <UINavigationControllerDelegate>

extern NSString * const SlideNavigationControllerDidOpen;
extern NSString *const SlideNavigationControllerDidClose;
extern NSString *const SlideNavigationControllerDidReveal;

@property (nonatomic, assign) BOOL avoidSwitchingToSameClassViewController;
@property (nonatomic, assign) BOOL enableSwipeGesture;
@property (nonatomic, assign) BOOL enableShadow;
Expand Down
28 changes: 27 additions & 1 deletion SlideMenu/Source/SlideNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ @interface SlideNavigationController() <UIGestureRecognizerDelegate>

@implementation SlideNavigationController

NSString * const SlideNavigationControllerDidOpen = @"SlideNavigationControllerDidOpen";
NSString * const SlideNavigationControllerDidClose = @"SlideNavigationControllerDidClose";
NSString *const SlideNavigationControllerDidReveal = @"SlideNavigationControllerDidReveal";

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define MENU_SLIDE_ANIMATION_DURATION .3
#define MENU_QUICK_SLIDE_ANIMATION_DURATION .18
Expand All @@ -51,6 +55,9 @@ @implementation SlideNavigationController
#define MENU_DEFAULT_SLIDE_OFFSET 60
#define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200
#define STATUS_BAR_HEIGHT 20
#define NOTIFICATION_USER_INFO_MENU_LEFT @"left"
#define NOTIFICATION_USER_INFO_MENU_RIGHT @"right"
#define NOTIFICATION_USER_INFO_MENU @"menu"

static SlideNavigationController *singletonInstance;

Expand Down Expand Up @@ -462,12 +469,16 @@ - (void)openMenu:(Menu)menu withDuration:(float)duration andCompletion:(void (^)
completion:^(BOOL finished) {
if (completion)
completion();

[self postNotificationWithName:SlideNavigationControllerDidOpen forMenu:menu];
}];
}

- (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completion
{
[self enableTapGestureToCloseMenu:NO];

Menu menu = (self.horizontalLocation > 0) ? MenuLeft : MenuRight;

[UIView animateWithDuration:duration
delay:0
Expand All @@ -480,6 +491,8 @@ - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completi
completion:^(BOOL finished) {
if (completion)
completion();

[self postNotificationWithName:SlideNavigationControllerDidClose forMenu:menu];
}];
}

Expand All @@ -488,6 +501,10 @@ - (void)moveHorizontallyToLocation:(CGFloat)location
CGRect rect = self.view.frame;
UIInterfaceOrientation orientation = self.interfaceOrientation;
Menu menu = (self.horizontalLocation >= 0 && location >= 0) ? MenuLeft : MenuRight;

if ((location > 0 && self.horizontalLocation <= 0) || (location < 0 && self.horizontalLocation >= 0)) {
[self postNotificationWithName:SlideNavigationControllerDidReveal forMenu:(location > 0) ? MenuLeft : MenuRight];
}

if (UIInterfaceOrientationIsLandscape(orientation))
{
Expand Down Expand Up @@ -596,6 +613,13 @@ - (CGFloat)horizontalSize
}
}

- (void)postNotificationWithName:(NSString *)name forMenu:(Menu)menu
{
NSString *menuString = (menu == MenuLeft) ? NOTIFICATION_USER_INFO_MENU_LEFT : NOTIFICATION_USER_INFO_MENU_RIGHT;
NSDictionary *userInfo = @{ NOTIFICATION_USER_INFO_MENU : menuString };
[[NSNotificationCenter defaultCenter] postNotificationName:name object:nil userInfo:userInfo];
}

#pragma mark - UINavigationControllerDelegate Methods -

- (void)navigationController:(UINavigationController *)navigationController
Expand Down Expand Up @@ -624,7 +648,6 @@ - (void)leftMenuSelected:(id)sender
[self closeMenuWithCompletion:nil];
else
[self openMenu:MenuLeft withCompletion:nil];

}

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

if (![self shouldDisplayMenu:currentMenu forViewController:self.topViewController])
return;

[self prepareMenuForReveal:currentMenu];

if (aPanRecognizer.state == UIGestureRecognizerStateBegan)
Expand Down
4 changes: 2 additions & 2 deletions SlideMenuTests/SlideMenuTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright (c) 2013 Aryan Ghassemi. All rights reserved.
//

#import <SenTestingKit/SenTestingKit.h>
#import <XCTest/XCTest.h>

@interface SlideMenuTests : SenTestCase
@interface SlideMenuTests : XCTestCase

@end
2 changes: 1 addition & 1 deletion SlideMenuTests/SlideMenuTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)tearDown

- (void)testExample
{
STFail(@"Unit tests are not implemented yet in SlideMenuTests");
XCTFail(@"Unit tests are not implemented yet in SlideMenuTests");
}

@end
4 changes: 2 additions & 2 deletions iOS-Slide-Menu.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = 'iOS-Slide-Menu'
s.version = '1.4.1'
s.version = '1.4.2'
s.summary = 'A Slide Menu for iOS'
s.homepage = 'https://github.com/aryaxt/iOS-Slide-Menu'
s.license = {
:type => 'MIT',
:file => 'License.txt'
}
s.author = {'Aryan Gh' => 'https://github.com/aryaxt/iOS-Slide-Menu'}
s.source = {:git => 'https://github.com/aryaxt/iOS-Slide-Menu.git', :tag => '1.4.1'}
s.source = {:git => 'https://github.com/aryaxt/iOS-Slide-Menu.git', :tag => '1.4.2'}
s.platform = :ios, '6.0'
s.source_files = 'SlideMenu/Source/*.{h,m}', 'SlideMenu/Source/Animations/*.{h,m}', 'SlideMenu/Source/Assets/*.{png}'
s.resources = ['SlideMenu/Source/Assets/**/*']
Expand Down

0 comments on commit 8137873

Please sign in to comment.