iOS开源项目:DYNavigationController
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的更多相关文章
- iOS开源项目周报0105
由OpenDigg 出品的iOS开源项目周报第四期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. He ...
- iOS开源项目周报1229
由OpenDigg 出品的iOS开源项目周报第三期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Ma ...
- iOS开源项目周报1222
由OpenDigg 出品的iOS开源项目周报第二期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. io ...
- iOS开源项目周报1215
由OpenDigg 出品的iOS开源项目周报第一期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开发方面的开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. PY ...
- 直接拿来用!最火的iOS开源项目
1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...
- (转)直接拿来用!最火的iOS开源项目(二)
“每一次的改变总意味着新的开始.”这句话用在iOS上可谓是再合适不过的了.GitHub上的iOS开源项目数不胜数,iOS每一次的改变,总会引发iOS开源项目的演变,从iOS 1.x到如今的iOS 7, ...
- (转)直接拿来用!最火的iOS开源项目(一)
1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...
- 40个GitHub上最受欢迎的iOS开源项目
40个GitHub上最受欢迎的iOS开源项目(一) http://www.weste.net/2013/8-1/92975.html 40个GitHub上最受欢迎的iOS开源项目(二) http:// ...
- 【转】GitHub平台最火的iOS开源项目——2013-08-25 17
http://www.cnblogs.com/lhming/category/391396.html 今天,我们将介绍20个在GitHub上非常受开发者欢迎的iOS开源项目,你准备好了吗? 1. AF ...
- iOS开源项目
在结束了GitHub平台上“最受欢迎的Android开源项目”系列盘点之后,我们正式迎来了“GitHub上最受欢迎的iOS开源项目”系列盘点.今天,我们将介绍20个在GitHub上非常受开发者欢迎的i ...
随机推荐
- 【LOJ】#2349. 「JOI 2017/2018 决赛」团子制作
题解 有意思的一个dp,我们对G计数,发现如果不在同一条对角线上的G肯定不会互相影响,所以我们对于每一条对角线dp dp的方式是枚举这个G以什么方式放,横着还是竖着,还是不放 代码 #include ...
- STL容器 -- Bitset
核心内容:Bitset 是 STL 中的二进制容器, 存放的时 bit 位元素, 每一位只占一个 bit 位, 取值 0 或者 1, 可以像整形元素一样按位与或非, 并且大大优化了时间和空间复杂度. ...
- 爱奇艺全国高校算法大赛初赛A
$01$背包. 数据范围:物品个数小于等于$3000$,背包大小小于等于$1000000$. $map<int,long long>dp$,用$map$去做$dp$,可以少遍历很多状态,可 ...
- redis环境搭建和java应用
安装 连接 Java连接redis 下载 wget http://download.redis.io/releases/redis-4.0.9.tar.gz 解压移动 tar -xvf redis-4 ...
- spring源码分析 contextConfigLocation属性的位置
<context-param> <param-name>contextConfigLocation</param-name> <param-value> ...
- JS模拟PHP的sleep
function sleep(n) { var start = new Date().getTime(); while(true) { if(new Date().getTime() - start ...
- FFTW3学习笔记3:FFTW 和 CUFFT 的使用对比
一.流程 1.使用cufftHandle创建句柄 2.使用cufftPlan1d(),cufftPlan3d(),cufftPlan3d(),cufftPlanMany()对句柄进行配置,主要是配置句 ...
- luogu P1965 转圈游戏
题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……,依此 ...
- NOI2005 维护数列(splay)
学了半天平衡树,选择了一道题来写一写,发现题目是裸的splay模板,但是还是写不好,这个的精髓之处在于在数列的某一个位置加入一个数列,类似于treap里面的merge,然后还学到了题解里面的的回收空间 ...
- Matrix-tree定理 spoj HIGH
Matrix-tree定理,给出一个无向图,问求出的生成树方案有多少种方案,利用Matrix-tree定理,主对角线第i行是i的度数,(i,j) 值为i和j之间边的数量,然后删去第一行第一列,利用初等 ...