diff --git a/SlideMenu/AppDelegate.m b/SlideMenu/AppDelegate.m index be29f9a..b233a8a 100644 --- a/SlideMenu/AppDelegate.m +++ b/SlideMenu/AppDelegate.m @@ -17,17 +17,23 @@ MenuViewController *rightMenu = (MenuViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MenuViewController"]; - rightMenu.view.backgroundColor = [UIColor whiteColor]; rightMenu.cellIdentifier = @"rightMenuCell"; MenuViewController *leftMenu = (MenuViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MenuViewController"]; - leftMenu.view.backgroundColor = [UIColor whiteColor]; leftMenu.cellIdentifier = @"leftMenuCell"; [SlideNavigationController sharedInstance].rightMenu = rightMenu; [SlideNavigationController sharedInstance].leftMenu = leftMenu; + // Creating a custom bar button for right menu + UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; + [button setImage:[UIImage imageNamed:@"menu-button"] forState:UIControlStateNormal]; + [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside]; + UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; + [SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem; + + // Override point for customization after application launch. return YES; } diff --git a/SlideMenu/Helper Classes/FriendsViewController.m b/SlideMenu/Helper Classes/FriendsViewController.m index 77c036a..38bc9a6 100644 --- a/SlideMenu/Helper Classes/FriendsViewController.m +++ b/SlideMenu/Helper Classes/FriendsViewController.m @@ -10,6 +10,10 @@ @implementation FriendsViewController +- (void)viewDidLoad +{ + [super viewDidLoad]; +} - (BOOL)slideNavigationControllerShouldDisplayLeftMenu { @@ -21,4 +25,16 @@ return NO; } +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return 20; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendCell"]; + cell.textLabel.text = [NSString stringWithFormat:@"Friend %d", indexPath.row]; + return cell; +} + @end diff --git a/SlideMenu/Helper Classes/MenuViewController.m b/SlideMenu/Helper Classes/MenuViewController.m index f7fac1b..a7aac5b 100755 --- a/SlideMenu/Helper Classes/MenuViewController.m +++ b/SlideMenu/Helper Classes/MenuViewController.m @@ -15,7 +15,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 4; + return 15; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -39,6 +39,10 @@ case 3: cell.textLabel.text = @"Sign Out"; break; + + default: + cell.textLabel.text = @"Random Cell"; + break; } return cell; @@ -69,6 +73,9 @@ [[SlideNavigationController sharedInstance] popToRootViewControllerAnimated:YES]; return; break; + + default: + return; } [[SlideNavigationController sharedInstance] switchToViewController:vc withCompletion:nil]; diff --git a/SlideMenu/Source/SlideNavigationController.h b/SlideMenu/Source/SlideNavigationController.h index b4ed7f9..6c990bd 100644 --- a/SlideMenu/Source/SlideNavigationController.h +++ b/SlideMenu/Source/SlideNavigationController.h @@ -63,5 +63,10 @@ typedef enum{ + (SlideNavigationController *)sharedInstance; - (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion; +- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion; +- (void)closeMenuWithCompletion:(void (^)())completion; +- (void)toggleLeftMenu; +- (void)toggleRightMenu; +- (BOOL)isMenuOpen; @end diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index b52d049..7e9a887 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -36,6 +36,7 @@ @implementation SlideNavigationController +#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 #define MENU_IMAGE @"menu-button" @@ -44,7 +45,8 @@ #define MENU_DEFAULT_SLIDE_OFFSET 60 #define MENU_FAST_VELOCITY_FOR_SWIPE_FOLLOW_DIRECTION 1200 #define MENU_REVEAL_ANIMATION_DEFAULT_SLIDE_MOVEMENT 100 -#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .9 +#define MENU_REVEAL_ANIMATION_DEFAULT_FADE_MAXIMUM_ALPHA .7 +#define STATUS_BAR_HEIGHT 20 static SlideNavigationController *singletonInstance; @@ -131,6 +133,11 @@ static SlideNavigationController *singletonInstance; CGRect rect = self.view.frame; self.leftMenu.view.frame = rect; self.rightMenu.view.frame = rect; + + // Move menus accordingly to avoid a weird animation during opening/closing menu after a rotation + [self updateMenuAnimation:MenuLeft]; + [self updateMenuAnimation:MenuRight]; + self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath; // we set shadowOpacity to 0 in willRotateToInterfaceOrientation, after the rotation we want to add the shadow back @@ -177,6 +184,33 @@ static SlideNavigationController *singletonInstance; } } +- (void)closeMenuWithCompletion:(void (^)())completion +{ + [self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; +} + +- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion +{ + [self openMenu:menu withDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; +} + +- (void)toggleLeftMenu +{ + [self toggleMenu:MenuLeft withCompletion:nil]; +} + +- (void)toggleRightMenu +{ + [self toggleMenu:MenuRight withCompletion:nil]; +} + +- (BOOL)isMenuOpen +{ + return (self.horizontalLocation == 0) ? NO : YES; +} + +#pragma mark - Override Methods - + - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated { if ([self isMenuOpen]) @@ -225,6 +259,14 @@ static SlideNavigationController *singletonInstance; #pragma mark - Private Methods - +- (void)toggleMenu:(Menu)menu withCompletion:(void (^)())completion +{ + if ([self isMenuOpen]) + [self closeMenuWithCompletion:completion]; + else + [self openMenu:menu withCompletion:completion]; +} + - (UIBarButtonItem *)barButtonItemForMenu:(Menu)menu { SEL selector = (menu == MenuLeft) ? @selector(leftMenuSelected:) : @selector(righttMenuSelected:); @@ -243,11 +285,6 @@ static SlideNavigationController *singletonInstance; } } -- (BOOL)isMenuOpen -{ - return (self.horizontalLocation == 0) ? NO : YES; -} - - (BOOL)shouldDisplayMenu:(Menu)menu forViewController:(UIViewController *)vc { if (menu == MenuRight) @@ -291,11 +328,6 @@ static SlideNavigationController *singletonInstance; }]; } -- (void)openMenu:(Menu)menu withCompletion:(void (^)())completion -{ - [self openMenu:menu withDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; -} - - (void)closeMenuWithDuration:(float)duration andCompletion:(void (^)())completion { [self.topViewController.view removeGestureRecognizer:self.tapRecognizer]; @@ -314,11 +346,6 @@ static SlideNavigationController *singletonInstance; }]; } -- (void)closeMenuWithCompletion:(void (^)())completion -{ - [self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion]; -} - - (void)moveHorizontallyToLocation:(CGFloat)location { CGRect rect = self.view.frame; @@ -353,6 +380,7 @@ static SlideNavigationController *singletonInstance; if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade) { + self.menuRevealFadeAnimationView.frame = menuViewController.view.bounds; [menuViewController.view addSubview:self.menuRevealFadeAnimationView]; self.menuRevealFadeAnimationView.alpha = self.menuRevealAnimationFadeMaximumAlpha - (self.menuRevealAnimationFadeMaximumAlpha *progress); } @@ -370,14 +398,29 @@ static SlideNavigationController *singletonInstance; location = (location < 0) ? 0 : location; CGRect rect = menuViewController.view.frame; + BOOL isIos7 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"); if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { rect.origin.y = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? location : location*-1; + + if (!isIos7) + { + // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20 + rect.origin.x = (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) ? 0 : STATUS_BAR_HEIGHT; + rect.size.width = self.view.frame.size.width-STATUS_BAR_HEIGHT; + } } else { rect.origin.x = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? location : location*-1; + + if (!isIos7) + { + // For some reasons in landscape belos the status bar is considered y=0, but in portrait it's considered y=20 + rect.origin.y = (self.interfaceOrientation == UIInterfaceOrientationPortrait) ? STATUS_BAR_HEIGHT : 0; + rect.size.height = self.view.frame.size.height-STATUS_BAR_HEIGHT; + } } menuViewController.view.frame = rect; @@ -395,7 +438,7 @@ static SlideNavigationController *singletonInstance; if (self.menuRevealAnimation == MenuRevealAnimationFade || self.menuRevealAnimation == MenuRevealAnimationSlideAndFade) { - menuViewController.view.alpha = self.menuRevealAnimationFadeMaximumAlpha; + self.menuRevealFadeAnimationView.alpha = self.menuRevealAnimationFadeMaximumAlpha; self.menuRevealFadeAnimationView.frame = menuViewController.view.bounds; } @@ -644,7 +687,6 @@ static SlideNavigationController *singletonInstance; if (!_menuRevealFadeAnimationView) { _menuRevealFadeAnimationView = [[UIView alloc] init]; - _menuRevealFadeAnimationView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; _menuRevealFadeAnimationView.backgroundColor = [UIColor blackColor]; _menuRevealFadeAnimationView.frame = self.view.bounds; } diff --git a/SlideMenu/en.lproj/MainStoryboard_iPad.storyboard b/SlideMenu/en.lproj/MainStoryboard_iPad.storyboard index 9fbe23e..d1659ff 100644 --- a/SlideMenu/en.lproj/MainStoryboard_iPad.storyboard +++ b/SlideMenu/en.lproj/MainStoryboard_iPad.storyboard @@ -1,25 +1,666 @@ - + - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard b/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard index 79373d0..b3f090d 100755 --- a/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard +++ b/SlideMenu/en.lproj/MainStoryboard_iPhone.storyboard @@ -1,11 +1,74 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26,25 +89,21 @@ - + - - - - - - - - @@ -70,14 +123,14 @@ - + - + @@ -96,58 +149,37 @@ - + - - - - - - - - - - - + + - - - - - - - - - - - @@ -159,49 +191,33 @@ - + - - - - - - + + + - - - - - + + + - - - - - - - - @@ -209,104 +225,56 @@ - - + + - - - + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - + + - - + - + - + - - - - - @@ -326,81 +290,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -416,7 +311,4 @@ - - - \ No newline at end of file