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. apache kafka系列之jmx监控指标参数

    https://blog.csdn.net/lizhitao/article/details/35986849

  2. IE7、IE8下使用escape、encodeURI传递中文参数乱码的问题及解决方案

    js跳转到指定页面,一旦escape()中文数据,浏览器就会终止和没有反应.上网搜了半天始终不得解.一种说法是,escape中文之后,url中出现了%u,IE7和IE8拒绝执行.目前看来差不多是这样的 ...

  3. IEEEXtreme 10.0 - Mancala'h

    这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Mancala'h 题目来源 第10届IEEE极限编程大赛 https://www.hackerrank.c ...

  4. Asp.net vNext 学习之路(一)

    概述 asp.net vNext 也叫 asp.net 5.0,意思是微软推出的下一个版本的asp.net.可以说是微软对asp.net的一个比较重大的重新设计, asp.net vNext是一 个比 ...

  5. 现在就能投入使用的12个高端大气上档次的CSS3特性

    原文:http://tutorialzine.com/2013/10/12-awesome-css3-features-you-can-finally-use/ 原文中有demo展示及下载. 翻译开始 ...

  6. 基于Redis实现——分布式锁与实现

    实现 使用的是jedis来连接Redis. 实现思想 获取锁的时候,使用setnx加锁,并使用expire命令为锁添加一个超时时间,超过该时间则自动释放锁,锁的value值为一个随机生成的UUID,通 ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  8. 【转】全面了解Mysql中的事务

    为什么要有事务? 事务广泛的运用于订单系统.银行系统等多种场景.如果有以下一个场景:A用户和B用户是银行的储户.现在A要给B转账500元.那么需要做以下几件事: 1. 检查A的账户余额>500元 ...

  9. iTerm2配置

    1.颜色Solarized 首先下载 Solarized: $ git clone git://github.com/altercation/solarized.git Terminal/iTerm2 ...

  10. bound和unbound方法,类的绑定和非绑定是什么

    作者:灵剑链接:https://www.zhihu.com/question/41006598/answer/148994582来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...