Sliding Menu for iOS by arturdev .
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:
- Slide menu with right menu only.
- Slide menu with left menu only.
- 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.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries installation in your projects.
pod "AMSlideMenu", "~> 1.5.3"
You can use AMSlideMenu with both static cells and dynamic cell prototypes.
Just follow this steps:
- Copy AMSlideMenu/AMSlideMenuForStoryboard folder to your project.
- Make a subclass of AMSlideMenuMainViewController. Assume you made MainVC.h and MainVC.m files (like in this project).
- Add a UIViewController to your iPhone's or iPad's storyboard and name it's class to MainVC and embed it in UINavigationController
- 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 this methods and return segue identifiers that you setted in previous step:
-(NSString *)segueIdentifierForIndexPathInLeftMenu:(NSIndexPath *)indexPath;
-(NSString *)segueIdentifierForIndexPathInRightMenu:(NSIndexPath *)indexPath;
Thats it, you are done.
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.
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 'AMSlideMenuProtocols'.
@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; }
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.