/AMSlideMenu

Sliding Menu for iOS (Left and Right menus). Multiple storyboards and XIBs support.

Primary LanguageObjective-CMIT LicenseMIT

AMSlideMenu

Sliding Menu for iOS by arturdev . Supported iOS version: >= 7.0


This is a simple library to create sliding menus that can be used in storyboards/xibs and supports static cells.

With this library you can create 3 types of sliding menus:

  1. Slide menu with right menu only.
  2. Slide menu with left menu only.
  3. Slide menu with both left and right menus.

This repo contains project that demonstrate usage of AMSlideMenu .
This project created in Xcode 5 , so this library is fully compatible with iOS 7.
Works for both iPhone and iPad.

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries installation in your projects.

Podfile

pod "AMSlideMenu", "~> 1.5.4"

USAGE WITH STORYBOARDS

Video Tutorial

You can use AMSlideMenu with both static cells and dynamic cell prototypes.

Just follow this steps:

  1. Copy AMSlideMenu/AMSlideMenuForStoryboard folder to your project.
  2. Make a subclass of AMSlideMenuMainViewController. Assume you made MainVC.h and MainVC.m files (like in this project).
  3. Add a UIViewController to your iPhone's or iPad's storyboard and name it's class to MainVC and embed it in UINavigationController
  4. For Left Menu:
           Add a UITableViewController to your storyboard and name it's class to any class that inherits from
           AMSlideMenuLeftTableViewController. Connect the AMSlideMenuMainViewController with your subclass with a custom        segue of type AMSlideMenuLeftMenuSegue, set the segue identifier to leftMenu.

    For Right Menu:
       Add a UITableViewController to your storyboard and name it's class to any class that inherits from
       AMSlideMenuRightTableViewController. Connect the AMSlideMenuMainViewController with your subclass with a custom        segue of type AMSlideMenuRightMenuSegue, set the segue identifier to rightMenu.

5. To add Content ViewController you have to to do the following:
       • Create your content view controller and embed it in a UINavigationController
       • Connect it to the AMSlideMenuLeftTableViewController or AMSlideMenuRightTableViewController with custom segue          AMSlideMenuContentSegue and set some identifier.
      If you want to use dynamic cells , then you have to perform segues in -tableView:didSelectRowAtIndexPath: method yourself.

6.. In MainVC.m override these methods and return segue identifiers that you setted in previous step:

-(NSString *)segueIdentifierForIndexPathInLeftMenu:(NSIndexPath *)indexPath;
-(NSString *)segueIdentifierForIndexPathInRightMenu:(NSIndexPath *)indexPath;

If you want to use multiple storyboards, or just want to use storyboard ids instead of segues, then override these methods:

-(UINavigationController *)navigationControllerForIndexPathInLeftMenu:(NSIndexPath *)indexPath;
-(UINavigationController *)navigationControllerForIndexPathInRightMenu:(NSIndexPath *)indexPath;

Thats it, you are done.

USAGE WITHOUT STORYBOARDS (XIB)

First of all you must add following line in your *-Prefix.pch file

#define AMSlideMenuWithoutStoryboards

For more info see demo project or this video tutorial.

Video Tutorial

CUSTOMIZATION

You can easily customize slide menu by overriding needed methods in you MainVC.m , such us:

- (AMPrimaryMenu)primaryMenu;
- (NSIndexPath *)initialIndexPathForLeftMenu;
- (NSIndexPath *)initialIndexPathForRightMenu;
- (NSString *)segueIdentifierForIndexPathInLeftMenu:(NSIndexPath *)indexPath;
- (NSString *)segueIdentifierForIndexPathInRightMenu:(NSIndexPath *)indexPath;
- (void)configureLeftMenuButton:(UIButton *)button;
- (void)configureRightMenuButton:(UIButton *)button;
- (CGFloat)leftMenuWidth;
- (CGFloat)rightMenuWidth;
- (void) configureSlideLayer:(CALayer *)layer;
- (CGFloat) panGestureWarkingAreaPercent;

You can use this methods in your MainVC.m if you want to open or close left or right menus programmatically:

- (void)openLeftMenu;
- (void)openLeftMenuAnimated:(BOOL)animated;
- (void)openRightMenu;
- (void)openRightMenuAnimated:(BOOL)animated;
- (void)closeLeftMenu;
- (void)closeLeftMenuAnimated:(BOOL)animated;
- (void)closeRightMenu;
- (void)closeRightMenuAnimated:(BOOL)animated;

If you want do add left/right menu button, or enable/disable pan gesture in you pushed view controller, then just import "UIViewController+AMSlideMenu.h" and call this methods from your pushed VC instance:
- (void)addLeftMenuButton;
- (void)addRightMenuButton;
- (void)disableSlidePanGestureForLeftMenu;
- (void)disableSlidePanGestureForRightMenu;
- (void)enableSlidePanGestureForLeftMenu;
- (void)enableSlidePanGestureForRightMenu;
e.g.
[self addLeftMenuButton];
Where self is your pushed VC.
If you want to get menu's open/close callbacks, then set MainVC's delegate property, and implement protocol named 'AMSlideMenuDelegate' which declared in 'AMSlideMenuProtocols.h'.
@optional
- (void)leftMenuWillOpen;
- (void)leftMenuDidOpen;
- (void)rightMenuWillOpen;
- (void)rightMenuDidOpen;
  • (void)leftMenuWillClose;
  • (void)leftMenuDidClose;
  • (void)rightMenuWillClose;
  • (void)rightMenuDidClose;

If you want to get MainVC's instance in any content VC, then call:

AMSlideMenuMainViewController *mainVC = [self mainSlideMenu];

Don't forget to import "UIViewController+AMSlideMenu.h" in your content VC.

If you want to programmatically change content vc to any vc at indexPath in your left/right menu then call
-(void)openContentViewControllerForMenu:(AMSlideMenu)menu atIndexPath:(NSIndexPath *)indexPath;

  AMSlideMenuMainViewController *mainVC = [self mainSlideMenu];
  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  [mainVC openContentViewControllerForMenu:AMSlideMenuRight atIndexPath:indexPath];

If you want to give deep effect to menus like in demo, then override in MainVC this funcion and return YES:

// Enabling Deepnes on left menu
- (BOOL)deepnessForLeftMenu
{
    return YES;
}

// Enabling Deepnes on right menu
- (BOOL)deepnessForRightMenu
{
    return YES;
}

SCREENSHOTS




Works great with UITableView "Swipe to delete" funtionality

Ideas

If you have any cool idea you would like to see in this lib or you found a bug please feel free to open an issue and tell about it :)

Thank You.