左右侧滑功能是比较常见的效果,此实例实现如下的效果:

这边使用到的SlideNavigationController开源类(引入源代码中的Source),其为NavigationController子类,在运用程序AppDelegate就设置为其根视图;主要代码如下:

1:AppDelegate主要代码如下:

#import "AppDelegate.h"
#import "SlideNavigationController.h"
#import "leftViewController.h"
#import "rightViewController.h"
#import "ViewController.h"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];self.window.backgroundColor = [UIColor whiteColor];    //设置根导航视图ViewController *homeVc = [[ViewController alloc] init];[self.window setRootViewController:[[SlideNavigationController alloc] initWithRootViewController:homeVc]];    //设置左右视图leftViewController* leftController=[[leftViewController alloc]init];rightViewController* rightController=[[rightViewController alloc]init];[SlideNavigationController sharedInstance].rightMenu = rightController;[SlideNavigationController sharedInstance].leftMenu = leftController;[SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;[self.window makeKeyAndVisible];return YES;
}

2:主页面ViewController代码:

#import <UIKit/UIKit.h>
#import "SlideNavigationController.h"
@interface ViewController : UIViewController<SlideNavigationControllerDelegate>@end

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor=[UIColor yellowColor];self.title=@"首页";UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];[button setTitle:@"右边" forState:UIControlStateNormal];[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];[button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside];UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];[SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem;
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}#pragma mark - SlideNavigationController Methods -- (BOOL)slideNavigationControllerShouldDisplayLeftMenu
{return YES;
}- (BOOL)slideNavigationControllerShouldDisplayRightMenu
{return YES;
}@end

注意要实现SlideNavigationControllerDelegate的两个是否有左跟右的菜单,还可以设置其导航栏的按键样式,如果没有设置会像左边出现的这种默认的;

3:左边视图leftViewController

#import <UIKit/UIKit.h>
#import "SlideNavigationController.h"
#import "OneViewController.h"
#import "TwoViewController.h"@interface leftViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>@end

#import "leftViewController.h"@interface leftViewController()
@property(nonatomic,strong)UITableView *tableView;
@property(strong,nonatomic) NSArray *listData;

@property(assign,nonatomic) bool slideOutAnimationEnabled;
@end@implementation leftViewController-(void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor=[UIColor redColor];[self ininLoadTable];
}-(void)ininLoadTable
{self.tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];self.tableView.delegate=self;self.tableView.dataSource=self;[self.view addSubview:self.tableView];self.listData=[[NSArray alloc] initWithObjects:@"朋友圈",@"个人好友",@"最近联系人", nil];
}#pragma mark - UITableView Delegate & Datasrouce -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.listData.count;
}- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)];view.backgroundColor = [UIColor clearColor];return view;
}- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{return 20;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];if (cell==nil) {cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];}cell.textLabel.text=self.listData[indexPath.row];cell.backgroundColor = [UIColor clearColor];return cell;
}//跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{UIViewController *vc ;switch (indexPath.row){case 0:vc = [[OneViewController alloc]init];break;case 1:vc = [[TwoViewController alloc]init];break;case 2:vc = [[OneViewController alloc]init];break;case 3:[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];[[SlideNavigationController sharedInstance] popToRootViewControllerAnimated:YES];return;break;}[[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:vcwithSlideOutAnimation:self.slideOutAnimationEnabledandCompletion:nil];
}
@end

注意:这边主要是进行导航跳转时要注意,popToRootViewControllerAnimated跟popToRootAndSwitchToViewController

4:右边的rightViewController

#import "rightViewController.h"@implementation rightViewController
-(void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor=[UIColor blueColor];
}
@end

附:另外二个插件也实现更好的效果,地址如下(https://github.com/JVillella/JVFloatingDrawer)效果图如下:

 另一个地址如下:(https://github.com/hujewelz/HUSliderMenu)效果图如下:

源代码下载地址:左右侧滑菜单源代码

转载于:https://www.cnblogs.com/wujy/p/4718002.html

左右侧滑菜单功能的实现相关推荐

  1. Android给ListView添加侧滑菜单功能

    贼简单,但是上次集成完之后忘记整理,所以写的有点简单 SwipeMenu类 继承自ViewGroup package com.onepilltest.others;import android.con ...

  2. Android 自定义控件打造史上最简单的侧滑菜单

    侧滑菜单在很多应用中都会见到,最近QQ5.0侧滑还玩了点花样~~对于侧滑菜单,一般大家都会自定义ViewGroup,然后隐藏菜单栏,当手指滑动时,通过Scroller或者不断的改变leftMargin ...

  3. Android自定义View之仿QQ侧滑菜单实现

    最近,由于正在做的一个应用中要用到侧滑菜单,所以通过查资料看视频,学习了一下自定义View,实现一个类似于QQ的侧滑菜单,顺便还将其封装为自定义组件,可以实现类似QQ的侧滑菜单和抽屉式侧滑菜单两种菜单 ...

  4. iOS之UI--使用SWRevealViewController实现侧边菜单功能详解实例

    使用SWRevealViewController实现侧边菜单功能详解 下面通过两种方法详解SWRevealViewController实现侧边菜单功能: 1.使用StoryBoard实现 2.纯代码实 ...

  5. html侧滑菜单mui,mui侧滑菜单点击含有mui-action-menu类的控件无法实现侧滑

    .mui-action-menu 标题栏 菜单按钮 指定href="#id"显示与隐藏侧滑菜单 html: 侧滑菜单列表 侧滑菜单列表2 侧滑菜单列表3 标题 具体内容 href: ...

  6. android.support.v7 fragme,打造最强RecyclerView侧滑菜单,长按拖拽Item,滑动删除Item

    前几天写了一片关于RecyclerView滑动删除Item,RecyclerView长按拖拽Item的博客,本来很简单一个使用,阅读量还挺高的,原博客传送门. 今天介绍一个RecyclerView I ...

  7. 第三方侧滑菜单SlidingMenu在android studio中的使用

    南尘:每天进步一点点! 前面讲了官方的侧滑菜单DrawerLayout的使用,其实早在官方没有推出这个之前,就有很多第三方的jar包如SlidingMenu等,感谢开源的力量. SlidingMenu ...

  8. Android组件——使用DrawerLayout仿网易新闻v4.4侧滑菜单

    转载请注明出处: http://blog.csdn.net/allen315410/article/details/42914501 概述 今天这篇博客将记录一些关于DrawerLayout的基本用法 ...

  9. 安卓之实现侧滑菜单DrawerLayout

    根据郭霖老师在他著作<第一行代码>中的介绍: Material Design Material Design是有谷歌的设计工程师们基于传统优秀的设计原则,结合丰富的创意和科学技术所发明的一 ...

最新文章

  1. 使用Python和OpenCV实现超快速,简单的伽玛校正功能
  2. BCH压力测试即将开始,你确定不来凑凑热闹?
  3. Git安装教程(Windows安装)
  4. Image打包流程-Android10.0编译系统(四)
  5. lay和lied_lie和lay的区别
  6. 使用cmd打开java文件,报错:“错误,编码GBK的不可映射字符”
  7. C++11 基于范围的 for 循环
  8. 基于 Jenkins 快速搭建持续集成环境--转
  9. net类库中发送电子邮件的方法总结
  10. python输出数字和字符串_(一)1-5Python数字和字符串
  11. 乌班图linux配置yum仓库,Linux系统的仓库配置(yum、epel)与软件安装(wireshark,wget,nginx)...
  12. SQL JOIN\SQL INNER JOIN 关键字\SQL LEFT JOIN 关键字\SQL RIGHT JOIN 关键字\SQL FULL JOIN 关键字...
  13. 通过 Lotus Domino Java 代理消费 Web 服务
  14. hadoop 2.6.5 + hive 集群搭建
  15. php url参数时间戳,AJAX GET 请求 URL 最后面缀的那个类似于时间戳的参数是什么啊?...
  16. OpenGL:关于获取渲染结果的深度信息的问题(二)
  17. qt 子窗口写到线程就卡死_Qt多线程创建
  18. (设计模式之一)浅析简单工厂模式
  19. java全局变量和局部变量_Java 10:局部变量类型推断
  20. 网络通讯技术在嵌入式系统中的应用

热门文章

  1. [YTU]_1985( C语言实验——保留字母)
  2. 【Kaggle-MNIST之路】CNN结构改进+改进过的损失函数(五)
  3. 《MySQL数据技术与实验指导》jxgl数据库的创建和插入
  4. 从电脑传PDF到IPad的阅读器上
  5. 微信从原版到现在所有界面图片_微信突然宣布:现在能改微信号了,所有人都能改...
  6. 【python】基础知识
  7. mqtt 异步消息 长连接 解析
  8. Spring Cloud学习笔记-010
  9. 运动框架实现思路(js)
  10. 第二次冲刺每日站立会议04