mmdrawercontroller


## What is MMDrawerController?

MMDrawerController is a versatile side drawer navigation container view controller designed to be used in iOS applications. It allows you to easily implement a sliding menu with various customization options.


## Key Features of MMDrawerController

MMDrawerController offers several key features:


### 1. Side Drawer Navigation

MMDrawerController provides a side drawer navigation pattern, with support for both left and right side drawers. This allows you to easily create a sliding menu that can be accessed by swiping from the side of the screen or by triggering a button.


### 2. Multiple Animation Options

You can choose from various animation options when opening or closing the side drawers. MMDrawerController supports both slide and slide-and-scale animations, giving you flexibility in how your navigation drawer is presented.


### 3. Gestures and Interactions

With MMDrawerController, you can customize the gestures and interactions associated with the side drawers. You can enable or disable swiping gestures, adjust the velocity required to trigger a swipe, and specify the pan gesture distance threshold.


### 4. Content View Controller Customization

MMDrawerController allows you to easily customize the content view controller that is displayed alongside the side drawer. You can adjust the shadow properties, specify animations, and add overlay views to enhance the user experience.


## Installation

Follow these steps to install MMDrawerController in your project:


### Step 1: Cocoapods Installation

Add the following line to your project’s Podfile:

“`shell
pod ‘MMDrawerController’
“`

Then, run the command `pod install` in your project directory on the Terminal. This will install the MMDrawerController library.


### Step 2: Import Header Files

Import the MMDrawerController header files into your project’s source files:

“`objective-c
#import
“`


### Step 3: Initialize and Configure

To use MMDrawerController, you need to initialize and configure it in your application. Here’s a basic example:

“`objective-c
#import
#import

// Create content view controller
UIViewController *contentViewController = [[UIViewController alloc] init];
contentViewController.view.backgroundColor = [UIColor whiteColor];

// Create left drawer view controller
UIViewController *leftDrawerViewController = [[UIViewController alloc] init];
leftDrawerViewController.view.backgroundColor = [UIColor lightGrayColor];

// Create right drawer view controller
UIViewController *rightDrawerViewController = [[UIViewController alloc] init];
rightDrawerViewController.view.backgroundColor = [UIColor darkGrayColor];

// Initialize MMDrawerController
MMDrawerController *drawerController = [[MMDrawerController alloc] initWithCenterViewController:contentViewController
leftDrawerViewController:leftDrawerViewController
rightDrawerViewController:rightDrawerViewController];

// Configure drawer controller properties
drawerController.maximumLeftDrawerWidth = 280.0;
drawerController.maximumRightDrawerWidth = 240.0;
drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
// … Add more customization as needed …

// Set drawer controller as the root view controller
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
window.rootViewController = drawerController;
“`


## Customization Options

MMDrawerController provides several customization options that allow you to tailor the behavior and appearance of the side drawers. Here are some key options:


### 1. Drawer Width

You can adjust the maximum width of the left and right drawers using the `maximumLeftDrawerWidth` and `maximumRightDrawerWidth` properties respectively. These values are specified in points.


### 2. Gesture Modes

The `openDrawerGestureModeMask` and `closeDrawerGestureModeMask` properties allow you to specify which types of gestures can trigger opening or closing the side drawer. The supported options include:

– `MMOpenDrawerGestureModeNone`
– `MMOpenDrawerGestureModePanningNavigationBar`
– `MMOpenDrawerGestureModePanningCenterView`
– `MMOpenDrawerGestureModeBezelPanningCenterView`
– `MMOpenDrawerGestureModeCustom`

– `MMCloseDrawerGestureModeNone`
– `MMCloseDrawerGestureModePanningNavigationBar`
– `MMCloseDrawerGestureModePanningCenterView`
– `MMCloseDrawerGestureModeBezelPanningCenterView`
– `MMCloseDrawerGestureModeTapNavigationBar`
– `MMCloseDrawerGestureModeTapCenterView`
– `MMCloseDrawerGestureModePanningDrawer`


### 3. Shadow Properties

You can customize the shadow properties of the side drawers using the `shadow*` properties provided by MMDrawerController. These properties include `shadowColor`, `shadowRadius`, `shadowOpacity`, and `shadowOffset`.


### 4. Animation Duration

The `animationDuration` property allows you to adjust the duration of the opening and closing animations. This value is specified in seconds.


### 5. Overlay Views

MMDrawerController supports adding overlay views that appear when the side drawers are open. You can use this feature to highlight or dim the content view controller while the side drawer is visible.


## Examples

To help you get started with MMDrawerController, here are a few examples showcasing different usage scenarios:


### Example 1: Basic Side Drawer Navigation

The following example demonstrates a basic implementation of MMDrawerController with a left side drawer:

“`objective-c
// Create content view controller
UIViewController *contentViewController = [[UIViewController alloc] init];
contentViewController.view.backgroundColor = [UIColor whiteColor];

// Create left drawer view controller
UIViewController *leftDrawerViewController = [[UIViewController alloc] init];
leftDrawerViewController.view.backgroundColor = [UIColor lightGrayColor];

// Initialize MMDrawerController
MMDrawerController *drawerController = [[MMDrawerController alloc] initWithCenterViewController:contentViewController
leftDrawerViewController:leftDrawerViewController];

// Configure drawer controller properties
drawerController.maximumLeftDrawerWidth = 280.0;
drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;

// Set drawer controller as the root view controller
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
window.rootViewController = drawerController;
“`


### Example 2: Custom Animation and Gesture Modes

In this example, we customize the animation and gesture modes for both the left and right side drawers:

“`objective-c
// Create content view controller
UIViewController *contentViewController = [[UIViewController alloc] init];
contentViewController.view.backgroundColor = [UIColor whiteColor];

// Create left drawer view controller
UIViewController *leftDrawerViewController = [[UIViewController alloc] init];
leftDrawerViewController.view.backgroundColor = [UIColor lightGrayColor];

// Create right drawer view controller
UIViewController *rightDrawerViewController = [[UIViewController alloc] init];
rightDrawerViewController.view.backgroundColor = [UIColor darkGrayColor];

// Initialize MMDrawerController
MMDrawerController *drawerController = [[MMDrawerController alloc] initWithCenterViewController:contentViewController
leftDrawerViewController:leftDrawerViewController
rightDrawerViewController:rightDrawerViewController];

// Configure drawer controller properties
drawerController.maximumLeftDrawerWidth = 280.0;
drawerController.maximumRightDrawerWidth = 240.0;
drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningNavigationBar | MMOpenDrawerGestureModeBezelPanningCenterView;
drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningNavigationBar | MMCloseDrawerGestureModeTapCenterView;

// Set drawer controller as the root view controller
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
window.rootViewController = drawerController;
“`


## Conclusion

MMDrawerController is a powerful tool for implementing side drawer navigation in your iOS applications. It provides a wide range of customization options and is easy to integrate into your project. By following the installation instructions and exploring the examples provided, you can quickly get started with MMDrawerController and enhance your app’s user experience.