开源库 RESideMenu
https://github.com/romaonthego/RESideMenu
使用
Code
In your AppDelegate's - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions create the view controller and assign content and menu view controllers.
// Create side menu controller // RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController leftMenuViewController:leftMenuViewController rightMenuViewController:rightMenuViewController]; sideMenuViewController.backgroundImage = [UIImage imageNamed:@"Stars"];
// Make it a root controller // self.window.rootViewController = sideMenuViewController;
Present the menu view controller:
or
Switch content view controllers:
....
[self.sideMenuViewController setContentViewController:viewController animated:YES]; [self.sideMenuViewController hideMenuViewController];
Storyboards Example
Create a subclass of RESideMenu. In this example we call it DEMORootViewController. In the Storyboard designate the root view's owner as DEMORootViewController. Make sure to #import "RESideMenu.h" in DEMORootViewController.h. Add more view controllers to your Storyboard, and give them identifiers "leftMenuViewController", "rightMenuViewController" and "contentViewController". Note that in the new XCode the identifier is called "Storyboard ID" and can be found in the Identity inspector. Add a method awakeFromNib to DEMORootViewController.m with the following code:
}