• 三分钟学会侧滑菜单栏


    一、先来看效果:

        

    二、废话不多说,首先就是搭建这个第三方框架环境,只需在你的Podfile文件中添加一行 pod 'ios-Slide-Menu'即可。

    三、创建ViewController,可只左划、可只右划、可左右划,按需创建相应的ViewController。

    四、添加左划右划相应方法

     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

    五、插入代码到AppDelegate中

     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设置的是左/右划时,显示主页面的偏移量

    2,[SlideNavigationController sharedInstance].leftBarButtonItem/rightBarButtonItem便是设置左右菜单导航按钮

    PS:三分钟过去了,你学会了吗?当然还有一些高阶用法,持续更新....

  • 相关阅读:
    linux部署docker镜像
    SpringBoot 定时任务篇
    POST形式 soapUI调用WebService的restful接口,传入json参数,并且返回json
    Java操作FTP工具类(实例详解)
    MyBatis逆向工程:根据table生成Model、Mapper、Mapper.xml
    Netty完成网络通信(二)
    NIO完成网络通信(一)
    MySQL5.6数据库8小时内无请求自动断开连接
    Eclipse集成Tomcat插件(特别简单)
    程序从sqlserver2008搬家到MySQL5.6
  • 原文地址:https://www.cnblogs.com/1016882435AIDA/p/7028494.html
Copyright © 2020-2023  润新知