1、先來看效果:ios
2、廢話很少說,首先就是搭建這個第三方框架環境,只需在你的Podfile文件中添加一行 pod 'ios-Slide-Menu'便可。app
3、建立ViewController,可只左劃、可只右劃、可左右劃,按需建立相應的ViewController。框架
4、添加左劃右劃相應方法ide
1 // 2 // CenterMenuController.m 3 // JoyfulPet 4 // 5 // Created by Aida He on 2017/6/16. 6 // Copyright © 2017年 Aida He. All rights reserved. 7 // 8 9 #import "CenterMenuController.h" 10 11 @interface CenterMenuController () 12 13 @end 14 15 @implementation CenterMenuController 16 17 - (void)viewDidLoad { 18 [super viewDidLoad]; 19 self.title = @"首頁"; 20 } 21 22 //容許左滑 23 - (BOOL)slideNavigationControllerShouldDisplayLeftMenu 24 { 25 return YES; 26 } 27 //容許右滑 28 - (BOOL)slideNavigationControllerShouldDisplayRightMenu 29 { 30 return YES; 31 } 32 33 - (void)didReceiveMemoryWarning { 34 [super didReceiveMemoryWarning]; 35 // Dispose of any resources that can be recreated. 36 } 37 38 /* 39 #pragma mark - Navigation 40 41 // In a storyboard-based application, you will often want to do a little preparation before navigation 42 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 43 // Get the new view controller using [segue destinationViewController]. 44 // Pass the selected object to the new view controller. 45 } 46 */ 47 48 @end
5、插入代碼到AppDelegate中spa
1 #import "SlideNavigationController.h" 2 #import "LeftMenuController.h" 3 #import "CenterMenuController.h" 4 #import "RightMenuController.h" 5 6 @interface AppDelegate () 7 8 @end 9 10 @implementation AppDelegate 11 12 13 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 14 // Override point for customization after application launch. 15 16 [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 17 18 19 [self.window setRootViewController:[[SlideNavigationController alloc] initWithRootViewController:[CenterMenuController new]]]; 20 RightMenuController *rightMenu = [RightMenuController new]; 21 LeftMenuController *leftMenu = [LeftMenuController new]; 22 [SlideNavigationController sharedInstance].leftMenu = leftMenu; 23 [SlideNavigationController sharedInstance].rightMenu = rightMenu; 24 25 [SlideNavigationController sharedInstance].portraitSlideOffset = 150;26 [SlideNavigationController sharedInstance].leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStyleDone target:[SlideNavigationController sharedInstance] action:@selector(toggleLeftMenu)]; 27 [SlideNavigationController sharedInstance].rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStyleDone target:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu)]; 28 29 return YES; 30 }
解析:1,[SlideNavigationController sharedInstance].portraitSlideOffset設置的是左/右劃時,顯示主頁面的偏移量code
2,[SlideNavigationController sharedInstance].leftBarButtonItem/rightBarButtonItem即是設置左右菜單導航按鈕blog
PS:三分鐘過去了,你學會了嗎?固然還有一些高階用法,持續更新....get