IOS的滑动菜单(Sliding Menu)的具体写法(附代码)
滑动菜单是一个很流行的IOS控件
先上效果图:
这里使用github的JTReveal框架来开发,链接是https://github.com/agassiyzh/JTRevealSidebarDemo/commit/ac03d9d7be4f1392020627e5fe8c22b972de4704
我们的ViewController要实现protocol JTRevealSidebarV2Delegate的两个optional方法
@optional
- (UIView *)viewForLeftSidebar;
- (UIView *)viewForRightSidebar;
- (UIView *)viewForLeftSidebar {
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
UITableView *view = self.leftSidebarView;
if ( ! view) {
view = self.leftSidebarView = [[UITableView alloc] initWithFrame:CGRectMake(0, mainFrame.origin.y, 270, mainFrame.size.height) style:UITableViewStylePlain];
view.dataSource = self;
view.delegate = self;
view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
view.backgroundColor = [UIColor whiteColor];
UIView* rightHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 42)];
rightHeaderView.backgroundColor = [UIColor whiteColor];
rightHeaderView.opaque = NO;
UILabel* lable = [[UILabel alloc] initWithFrame:CGRectMake(90, 2, 100, 38)];
[lable setText:@"left view"];
UIFont* font = [UIFont systemFontOfSize:20];
lable.font = font;
[rightHeaderView addSubview:lable];
UIView* lines = [[UIView alloc] initWithFrame:CGRectMake(0, 42, 300, 2)];
lines.backgroundColor = [UIColor lightGrayColor];
[rightHeaderView addSubview:lines];
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(213, 2, 53, 38)];
[button setTitle:@"Edit" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(leftButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[rightHeaderView addSubview:button];
view.tableHeaderView = rightHeaderView;
}
return view;
}
在ViewController先初始化title
-(void) addTilteBar{
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStylePlain target:self action:@selector(showLeftSidebar:)];
self.navigationItem.leftBarButtonItem = back;
[back release];
NSArray* array = [[NSArray alloc] initWithObjects:@"Left Tab",@"Right Tab",nil];
UISegmentedControl* segment = [[UISegmentedControl alloc] initWithItems:array];
CGRect rect = CGRectMake(80.0f, 8.0f, 170.0f, 30.0f);
segment.frame = rect;
segment.segmentedControlStyle = UISegmentedControlStyleBar;
segment.selectedSegmentIndex = -1;
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
[segment release];
UIBarButtonItem *mapButton = [[UIBarButtonItem alloc]
initWithTitle:@"右边"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(revealRightSidebar:)];
// [button2 addTarget:self action:@selector(revealRightSidebar:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = mapButton;
self.navigationItem.revealSidebarDelegate = self;
[mapButton release];
点击左边的事件是
- (void)showLeftSidebar:(id)sender {
JTRevealedState state = JTRevealedStateLeft;
if (self.navigationController.revealedState == JTRevealedStateLeft) {
state = JTRevealedStateNo;
}
[self.navigationController setRevealedState:state];
}
界面中这些tableview的Delegate和dataSource共用一个
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.rightSidebarView) {
return [RightArray count];
}else if(tableView == self.leftSidebarView) {
return [leftArray count];
}else{
return [names count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.rightSidebarView) {
static NSString *CellIdentifier = @"rightcell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSUInteger row = [indexPath row];
// NSUInteger section = [indexPath section];
// cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = [RightArray objectAtIndex:row];
return cell;
} else if(tableView == self.leftSidebarView) {
static NSString *CellIdentifier = @"left_cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSUInteger row = [indexPath row];
// NSUInteger section = [indexPath section];
// cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = [leftArray objectAtIndex:row];
return cell;
}else {
static NSString *TableSampleIdentifier = @"TableSampleIdentifier";
// UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableSampleIdentifier];
cell.textLabel.text = [names objectAtIndex:indexPath.row];
return cell;
}
}
IOS的滑动菜单(Sliding Menu)的具体写法(附代码)的更多相关文章
- iOS顶部滑动菜单:FDSlideBar 与NinaPagerView
FDSlideBar 是一个顶部滑动菜单,如常见的网易.腾讯新闻等样式.该控件支持自定颜色.字体等多种样式风格.菜单间切换流畅,具有较好的体验性.下部的内容展示经过挣 扎,最后选择了 UITableV ...
- Android 学习笔记之AndBase框架学习(七) SlidingMenu滑动菜单的实现
PS:努力的往前飞..再累也无所谓.. 学习内容: 1.使用SlidingMenu实现滑动菜单.. SlidingMenu滑动菜单..滑动菜单在绝大多数app中也是存在的..非常的实用..Gith ...
- IOS学习之路十(仿人人滑动菜单Slide-out Sidebar Menu)
最近滑动菜单比较流行,像facebook和人人等都在使用滑动菜单,今天做了一个小demo大体效果如下: 这次用了一个开源的项目ECSlidingViewController这个也是一个挺著名的托管在G ...
- ionic教程之Win10环境下ionic+angular实现滑动菜单及列表
写博客,不容易,你们的评论和转载,就是我的动力,但请注明出处,隔壁老王的开发园:http://www.cnblogs.com/titibili/p/5124940.html 2016年1月11日 21 ...
- Android UI(三)SlidingMenu实现滑动菜单(详细 官方)
Jeff Lee blog: http://www.cnblogs.com/Alandre/ (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks ...
- bootstrap-简单实用的垂直手风琴滑动菜单列表特效
前端: <html lang="zh"> <head> <meta charset="UTF-8"> <meta ht ...
- html5手机端的点击弹出侧边滑动菜单代码
效果预览:http://hovertree.com/texiao/html5/19/ 本效果适用于移动设备,可以使用手机等浏览效果. 源码下载:http://hovertree.com/h/bjaf/ ...
- Android 滑动菜单框架--SwipeMenuListView框架完全解析
SwipeMenuListView(滑动菜单) A swipe menu for ListView.--一个非常好的滑动菜单开源项目. Demo 一.简介 看了挺长时间的自定义View和事件分发,想找 ...
- Android 3D滑动菜单完全解析,实现推拉门式的立体特效
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10471245 在上一篇文章中,我们学习了Camera的基本用法,并借助它们编写了一 ...
随机推荐
- Resharper 使用帮助-自动生成文件头
VS2012 安装完resharper 后,在resharper选项中选择 Code Editing – File Header Text . 输入自定义的文件头格式.如果需要在文件头外层添加regi ...
- 【转】Apache服务器的下载与安装
PHP的运行必然少不了服务器的支持,何为服务器?通俗讲就是在一台计算机上,安装个服务器软件,这台计算机便可以称之为服务器,服务器软件和计算机本身的操作系统是两码事,计算机自身的操作系统可以为linux ...
- IDEA 构建为了打 jar 包的工程,包含 maven 打 jar 包的过程
前言:最近自己写了一个单表查询的组件,包含前端.后台,所以需要向阿里的 druid 一样将所有文件打到一个 jar 包里,这里首先记录如何打 jar 包. 附:自己的一个 jar 包源码 https: ...
- markdown 语法备忘
markdwon语法, 增加以下CSS代码,可以对markdwon语法产生的文件进行分页操作. <div style="page-break-after:always;"&g ...
- 0<Double.MIN_VALUE
好吧, 吐嘈一下: 前几天写代码时发现 Double 有几个静态成员变量, 如 MAX_VALUE , MIN_VALUE 等, 当时就自己"故名思意"了, 分别当成了 doubl ...
- Hibernate初学
什么是Hibernate? Hibernate,翻译过来是冬眠的意思,正好现在已经进入秋季,世间万物开始准备冬眠了.其实对于对象来说就是持久化. 我们从三个角度理解一下Hibernate: 一.Hib ...
- 献给java求职路上的你们
为了更好的树立知识体系,我附加了相关的思维导图,分为pdf版和mindnote版.比如java相关的导图如下: 由于时间仓促,有些地方未写完,后面会继续补充.如有不妥之处,欢迎及时与我沟通. 相关概念 ...
- Spring Boot—09通过Form提交的映射
package com.sample.smartmap.controller; import org.springframework.beans.factory.annotation.Autowire ...
- Struts2中 Path (getContextPath与basePath)
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径. 虽然可以用redirect方式解决,但redirect方式并非必要.解决办法非常简单,统一使用绝对 ...
- srop实战
前言 srop 的作用比较强,在条件允许的情况下,尽量使用它.题目来自于 i春秋的一个比赛. 题目链接: https://gitee.com/hac425/blog_data/blob/master/ ...