DYNavigationController是一个实现了左右滑动导航的项目。

https://github.com/dyang/DYNavigationController

首先用之前的跟视图初始化DYNavigationController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch.
RootViewController *rootViewController = [[[RootViewController alloc] init] autorelease];
DYNavigationController *navigationController = [[[DYNavigationController alloc]
initWithRootViewController:rootViewController] autorelease]; self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}

这个方法定义了左右滑动的手势操作

- (void)setUpGestureRecognizers:(UIViewController *)viewController {
// Swipe right: pop the current view and go back one level
UISwipeGestureRecognizer *rightSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(popCurrentViewOut:)];
rightSwipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[viewController.view addGestureRecognizer:rightSwipeGesture];
[rightSwipeGesture release]; // Swipe left: push a new view
UISwipeGestureRecognizer *leftSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(pushNewViewIn:)];
leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[viewController.view addGestureRecognizer:leftSwipeGesture];
[leftSwipeGesture release];
}

当向右滑动的时候,当前的视图会被移动的屏幕的左边,并加入到导航的栈里

- (void)pushViewController:(UIViewController *)viewController {
// Place the new view to the right next to the current view
viewController.view.frame = CGRectOffset(self.view.bounds, self.view.bounds.size.width, ); // Add the new view to our view hierarchy so that it displays on screen.
[self.view addSubview:viewController.view]; // Start animation
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationCurveEaseInOut animations:^{
[self currentViewController].view.frame = CGRectOffset(self.view.bounds, -self.view.bounds.size.width, );
viewController.view.frame = self.view.bounds;
} completion:^(BOOL finished) {
if (finished) {
// Connect DYNavigationController to viewController if needed
[self setNavigatorIfNeeded:viewController]; // Set up gesture recognizer so that we can respond to swipes
[self setUpGestureRecognizers:viewController]; // Add the new controller to our viewControllerStack
[self.viewControllerStack addObject:viewController];
}
}];
}

这里使用了UIView的类方法animateWithDuration实现了跳转的动画。

当向左滑动的时候,当前视图被移除导航栈,左边的视图向右移到屏幕中央。

- (void)popViewController {
// Sanity check - We only pop when there are at least two viewControllers in the stack,
// otherwise there is nothing to pop
if (self.viewControllerStack.count < ) return; // Start animation
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationCurveEaseInOut animations:^{
[self currentViewController].view.frame = CGRectOffset(self.view.bounds, self.view.bounds.size.width, );
[self previousViewController].view.frame = self.view.bounds;
} completion:^(BOOL finished) {
if (finished) {
// Tear down gesture recognizers
[self tearDownGestureRecognizers:[self currentViewController]]; // Remove current viewController.view from self.
[[self currentViewController].view removeFromSuperview]; // Remove current viewController from self.
[[self currentViewController] removeFromParentViewController]; // Remove current view controller from viewControllerStack
[self.viewControllerStack removeLastObject];
}
}];
}

导航的具体实现在DYNavigationController中,DYNavigationControllerDelegate持有一个DYNavigationController的property,在RootViewController中进行了synthesize,RootViewController实现了DYNavigationControllerDelegate协议,DetailViewController也实现了DYNavigationControllerDelegate协议,所以DetailViewController中可以直接使用这个DYNavigationController的引用,来实现导航功能。

iOS开源项目:DYNavigationController的更多相关文章

  1. iOS开源项目周报0105

    由OpenDigg 出品的iOS开源项目周报第四期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. He ...

  2. iOS开源项目周报1229

    由OpenDigg 出品的iOS开源项目周报第三期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Ma ...

  3. iOS开源项目周报1222

    由OpenDigg 出品的iOS开源项目周报第二期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. io ...

  4. iOS开源项目周报1215

    由OpenDigg 出品的iOS开源项目周报第一期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. PY ...

  5. 直接拿来用!最火的iOS开源项目

    1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...

  6. (转)直接拿来用!最火的iOS开源项目(二)

    “每一次的改变总意味着新的开始.”这句话用在iOS上可谓是再合适不过的了.GitHub上的iOS开源项目数不胜数,iOS每一次的改变,总会引发iOS开源项目的演变,从iOS 1.x到如今的iOS 7, ...

  7. (转)直接拿来用!最火的iOS开源项目(一)

    1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...

  8. 40个GitHub上最受欢迎的iOS开源项目

    40个GitHub上最受欢迎的iOS开源项目(一) http://www.weste.net/2013/8-1/92975.html 40个GitHub上最受欢迎的iOS开源项目(二) http:// ...

  9. 【转】GitHub平台最火的iOS开源项目——2013-08-25 17

    http://www.cnblogs.com/lhming/category/391396.html 今天,我们将介绍20个在GitHub上非常受开发者欢迎的iOS开源项目,你准备好了吗? 1. AF ...

  10. iOS开源项目

    在结束了GitHub平台上“最受欢迎的Android开源项目”系列盘点之后,我们正式迎来了“GitHub上最受欢迎的iOS开源项目”系列盘点.今天,我们将介绍20个在GitHub上非常受开发者欢迎的i ...

随机推荐

  1. CentOS7中开机出现end_request:I/O error,dev fd0,sector 0的解决办法

    https://blog.csdn.net/wangjinyang_123/article/details/40583635

  2. Loadrunner中cookie解释与用法

    loadrunner对于cookie的处理loadrunner中与cookie处理相关的常用函数如下: web_add_cookie():添加新的cookie或者修改已经存在的cookie web_r ...

  3. ZOJ 3613 Wormhole Transport

    斯坦纳树,$dp$. 先求出每个状态下连通的最小花费,因为可以是森林,所以$dp$一下. #include<bits/stdc++.h> using namespace std; int ...

  4. Python的环境搭建——万丈高楼平地起

    Python的环境搭建,远程连接,端口映射,虚拟机 写在正文之前 python语言的开发环境还是相对比较简单的,但是也是有很多需要注意的地方,对于初次接触python或者以前很少用到虚拟环境的朋友来说 ...

  5. JSP与Servlet传值及对比

    JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是”类servlet”. Servlet和JSP最主要的不同点在于,Servlet的应用逻辑是在 ...

  6. FastReport.Net使用:[26]数字格式

    1.数据包含固定格式的小数,自由格式的小数,以及字符串格式等四列数据.包含3行数据(1.2,1.23,1.234). 以下为Access数据视图和FastReport.Net报表设计器中的数据视图. ...

  7. HDU 1272(并查集)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. 【BZOJ 2728】 2728: [HNOI2012]与非 (线性基?)

    2728: [HNOI2012]与非 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 813  Solved: 389 Description Inpu ...

  9. 活动a 使用 启动为结果 方法 启动 活动 b, b什么都不做 并返回给a,a中的 在活动结果时候 回调 是否被执行?

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 活动a 使用 启动为结果 方法 启动 活动 b, b什么都不做 并返回给a,a中的 在活 ...

  10. NOIP2017 D1T2时间复杂度

    这道题在考试时看到感觉与第一题放反了位置(因为我还没有看到第一题是结论题) 对于每个语句进行栈的模拟,而如果有语法错误就特判. 对于每一条for语句我们将其与栈顶元素连边,复杂度是1的我们不用考虑,如 ...