|
1 |
| -# MFSideMenu |
2 |
| -======= |
| 1 | +#MFSideMenu |
3 | 2 |
|
4 |
| -This project was inspired by the Facebook iOS app. The idea is to give a slideout menu to a UINavigationController-based app. |
| 3 | +This project was inspired by the side-menu functionality seen in the Facebook iOS app. MFSideMenu utilizes view controller containment and gives you a simple API for implementing side-menu functionality. It integrates with storyboard-based apps as well as traditional setups. |
5 | 4 |
|
6 | 5 | =======
|
7 | 6 |
|
8 |
| -[ |
9 |
| -[ |
| 7 | +  |
| 8 | + |
| 9 | +##Features |
10 | 10 |
|
11 |
| -Features |
12 |
| -======= |
13 | 11 | - Universal device support (iPhone + iPad)
|
14 | 12 | - Universal orientation support (Portrait + Landscape)
|
15 |
| -- The menu can display on the left or right side of the screen. |
16 |
| -- Support for UINavigationController or UITabBarController as the window's rootViewController. |
17 |
| -- Toggle the menu by pressing the UIBarButtonItem or by dragging your UINavigationController to the side. |
18 |
| -- When the menu is visible you can tap or drag it back to the closed position. |
19 |
| -- Optional shadow between UINavigationController and menu |
| 13 | +- Menus on the left and right side of the screen. |
| 14 | +- Storyboard support |
| 15 | +- View controller containment |
| 16 | +- Works with UINavigationController, UITabBarController, and other types of view controllers |
| 17 | +- Nice set of configuration options |
20 | 18 | - Lightweight, simple and readable code.
|
21 | 19 |
|
22 | 20 |
|
23 |
| -Basic Setup |
24 |
| -======= |
25 |
| -The example project shows how to use the full configuration. It also includes an example of how to use the app with a UITabBarController. MFSideMenu uses ARC. If you have a project that doesn't use ARC, just add the `-fobjc-arc` compiler flag to the MFSideMenu files. |
| 21 | +##Installation |
26 | 22 |
|
27 |
| -Note: QuartzCore is required for shadow rendering |
| 23 | +####CocoaPods |
| 24 | +Add `pod 'MFSideMenu'` to your Podfile. |
28 | 25 |
|
29 |
| -1. Bring the MFSideMenu folder into your project. |
30 |
| -2. Create your menu (a UITableViewController -- in the demo this is the SideMenuViewController class) |
31 |
| -3. Initiate MFSideMenu in your app delegate:<br /> |
32 |
| - ```objective-c |
33 |
| - MFSideMenu *sideMenu = [MFSideMenu menuWithNavigationController:navigationController |
34 |
| - leftSideMenuController:leftSideMenuController |
35 |
| - rightSideMenuController:rightSideMenuController]; |
36 |
| - |
37 |
| - self.window.rootViewController = navigationController; |
38 |
| - [self.window makeKeyAndVisible]; |
39 |
| - ``` |
| 26 | +####Manually |
| 27 | +Add the `MFSideMenu` folder to your project. Add QuartzCore to your project. MFSideMenu uses ARC. If you have a project that doesn't use ARC, just add the `-fobjc-arc` compiler flag to the MFSideMenu files. |
40 | 28 |
|
41 | 29 |
|
42 |
| -Configuration |
43 |
| -======= |
44 |
| -Checkout MFSideMenu.h to get the full gist of the configuration options. |
| 30 | +##Usage |
45 | 31 |
|
46 |
| -- **MFSideMenuPanMode** lets you control the areas that can be panned in order to show the menu. You can use this to disable panning on the UINavigationBar or on the body of the UINavigationController. |
47 |
| -- **MFSideMenuState** tells you the current state of the menu (left menu open, right menu open, or closed) |
48 |
| -- **MFSideMenuStateEventBlock** can be used to receive notifications of MFSideMenuStateEvents. You can do this like so:<br /> |
| 32 | +###Basic Setup |
49 | 33 |
|
| 34 | +In your app delegate:<br /> |
50 | 35 | ```objective-c
|
51 |
| - self.navigationController.sideMenu.menuStateEventBlock = ^(MFSideMenuStateEvent event) { |
52 |
| - switch (event) { |
53 |
| - case MFSideMenuStateEventMenuWillOpen: |
54 |
| - // the menu will open |
55 |
| - break; |
56 |
| - case MFSideMenuStateEventMenuDidOpen: |
57 |
| - // the menu finished opening |
58 |
| - break; |
59 |
| - case MFSideMenuStateEventMenuWillClose: |
60 |
| - // the menu will close |
61 |
| - break; |
62 |
| - case MFSideMenuStateEventMenuDidClose: |
63 |
| - // the menu finished closing |
64 |
| - break; |
65 |
| - } |
66 |
| - }; |
| 36 | +#import "MFSideMenu.h" |
| 37 | + |
| 38 | +MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController |
| 39 | + containerWithCenterViewController:centerViewController |
| 40 | + leftMenuViewController:leftMenuViewController |
| 41 | + rightMenuViewController:rightMenuViewController]; |
| 42 | +self.window.rootViewController = container; |
| 43 | +[self.window makeKeyAndVisible]; |
67 | 44 | ```
|
68 |
| - |
69 |
| -Contact |
70 |
| -======= |
| 45 | +
|
| 46 | +###Opening & Closing Menus |
| 47 | +
|
| 48 | +```objective-c |
| 49 | +// toggle the left side menu |
| 50 | +[self.menuContainerViewController toggleLeftSideMenuCompletion:^{}]; |
| 51 | +// toggle the right side menu |
| 52 | +[self.menuContainerViewController toggleRightSideMenuCompletion:^{}]; |
| 53 | +// close the side menu |
| 54 | +[self.menuContainerViewController setMenuState:MFSideMenuStateClosed]; |
| 55 | +// open the left side menu |
| 56 | +[self.menuContainerViewController setMenuState:MFSideMenuStateLeftMenuOpen]; |
| 57 | +// open the right side menu |
| 58 | +[self.menuContainerViewController setMenuState:MFSideMenuStateRightMenuOpen]; |
| 59 | +``` |
| 60 | + |
| 61 | +###Pan Modes |
| 62 | + |
| 63 | +You can specify which areas you want to allow pan gestures on: |
| 64 | + |
| 65 | +```objective-c |
| 66 | +// enable panning on the center view controllers & the side menus (this is the default behavior): |
| 67 | +menuContainerViewController.panMode = MFSideMenuPanModeCenterViewController | MFSideMenuPanModeSideMenu; |
| 68 | + |
| 69 | +// disable panning on the side menus, only allow panning on the center view controller: |
| 70 | +menuContainerViewController.panMode = MFSideMenuPanModeCenterViewController; |
| 71 | + |
| 72 | +// disable all panning |
| 73 | +menuContainerViewController.panMode = MFSideMenuPanModeNone; |
| 74 | +``` |
| 75 | + |
| 76 | + |
| 77 | +###Listening for Menu Events |
| 78 | + |
| 79 | +You can listen for menu state event changes (i.e. menu will open, menu did open, etc.). See MFSideMenuContainerViewController.h for the different types of events. |
| 80 | + |
| 81 | +```objective-c |
| 82 | +[[NSNotificationCenter defaultCenter] addObserver:self |
| 83 | + selector:@selector(menuStateEventOccurred:) |
| 84 | + name:MFSideMenuStateNotificationEvent |
| 85 | + object:nil]; |
| 86 | +- (void)menuStateEventOccurred:(NSNotification *)notification { |
| 87 | + MFSideMenuStateEvent event = [[[notification userInfo] objectForKey:@"eventType"] intValue]; |
| 88 | + MFSideMenuContainerViewController *containerViewController = notification.object; |
| 89 | + // ... |
| 90 | +} |
| 91 | +``` |
| 92 | +
|
| 93 | +###Menu Slide Animation |
| 94 | +
|
| 95 | +With this option enabled, the side menus will slide in & out with the center view controller. This effect is similar to the Wunderlist side menu. |
| 96 | +
|
| 97 | +```objective-c |
| 98 | +// enable the menu slide animation |
| 99 | +[menuContainerViewController setMenuSlideAnimationEnabled:YES]; |
| 100 | +
|
| 101 | +// control the exaggeration of the menu slide animation |
| 102 | +[menuContainerViewController setMenuSlideAnimationFactor:3.0f]; |
| 103 | +``` |
| 104 | + |
| 105 | +###Shadow |
| 106 | + |
| 107 | +MFSideMenu gives you the option to show a shadow between the center view controller & the side menus. |
| 108 | + |
| 109 | +```objective-c |
| 110 | +// enable/disable the shadow |
| 111 | +[menuContainerViewController setShadowEnabled:YES]; |
| 112 | + |
| 113 | +// set the radius of the shadow |
| 114 | +[menuContainerViewController setShadowRadius:10.0f]; |
| 115 | + |
| 116 | +// set the color of the shadow |
| 117 | +[menuContainerViewController setShadowColor:[UIColor blackColor]]; |
| 118 | + |
| 119 | +// set the opacity of the shadow |
| 120 | +[menuContainerViewController setShadowOpacity:0.75f]; |
| 121 | + |
| 122 | +``` |
| 123 | +
|
| 124 | +##Contact |
71 | 125 |
|
72 | 126 |
|
73 | 127 | http://viamike.com<br />
|
|
0 commit comments