iOS5中,UIViewController新添加了几个方法:

- (void)addChildViewController:(UIViewController *)childController NS_AVAILABLE_IOS(5_0);
- (void) removeFromParentViewController NS_AVAILABLE_IOS(5_0); - (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(5_0); - (void)willMoveToParentViewController:(UIViewController *)parent NS_AVAILABLE_IOS(5_0);
- (void)didMoveToParentViewController:(UIViewController *)parent NS_AVAILABLE_IOS(5_0);

代码示例:

代码结构:

其中,MainViewController添加为window的rootViewController,FirstViewController、SecondViewController、ThirdViewController就是三个简单的controller,设置不同的背景色即可,MainViewController的xib文件如下图:

MainViewController的viewDidLoad方法实现如下:

- (void)viewDidLoad
{
[super viewDidLoad]; FirstViewController * firstController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self addChildViewController:firstController]; SecondViewController * secondController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self addChildViewController:secondController]; ThirdViewController * thirdController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self addChildViewController:thirdController]; [contentView addSubview:firstController.view];//用于显示其它controller的view
currentController = firstController;
}

三个button的响应方法如下:

- (IBAction)onButtonClick:(id)sender {
FirstViewController * firstController = self.childViewControllers[];
SecondViewController * secondController = self.childViewControllers[];
ThirdViewController * thirdController = self.childViewControllers[];
NSInteger tag = ((UIButton *) sender).tag;
if ((currentController == firstController && tag == ) || (currentController == secondController && tag == ) || (currentController == thirdController && tag == )) {
return;
} UIViewController * oldController = currentController; switch (tag) {
case :{ [self transitionFromViewController:currentController toViewController:firstController duration: options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{} completion:^(BOOL finished) {
if (finished) {
currentController = firstController;
}
else {
currentController = oldController;
}
}];
break;
} case : {
[self transitionFromViewController:currentController toViewController:secondController duration: options:UIViewAnimationOptionTransitionFlipFromTop animations:^{} completion:^(BOOL finished) {
if (finished) {
currentController = secondController;
}
else {
currentController = oldController;
}
}];
break;
} case :{
[self transitionFromViewController:currentController toViewController:thirdController duration: options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{} completion:^(BOOL finished) {
if (finished) {
currentController = thirdController;
}
else {
currentController = oldController;
}
}];
break;
}
default:
break;
}
}

效果图:

     

UIViewController新方法的使用(transitionFromViewController:toViewController:duration:options:animations:completion:)的更多相关文章

  1. iOS5中UIViewController的新方法

    iOS5中UIViewController的新方法 前言 在苹果的 WWDC2011 大会视频的<Session 101 - What's New in Cocoa> 和<Sessi ...

  2. 【C#代码实战】群蚁算法理论与实践全攻略——旅行商等路径优化问题的新方法

    若干年前读研的时候,学院有一个教授,专门做群蚁算法的,很厉害,偶尔了解了一点点.感觉也是生物智能的一个体现,和遗传算法.神经网络有异曲同工之妙.只不过当时没有实际需求学习,所以没去研究.最近有一个这样 ...

  3. 【Android】一种提高Android应用进程存活率新方法

    [Android]一种提高Android应用进程存活率新方法 SkySeraph Jun. 19st 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph ...

  4. Execel(导出新方法):

    #region 新方法 //var sbHtml = new StringBuilder(); //sbHtml.Append("<table border='1' cellspaci ...

  5. 交换ctrl和caps_loack的新方法

    交换ctrl和caps_loack的新方法 Table of Contents 1 过程 1 过程 debian用了几年,由于emacs的关系,一直将右ctrl和caps_lock键交换,使用的是xm ...

  6. MVC导出数据到EXCEL新方法:将视图或分部视图转换为HTML后再直接返回FileResult

    导出EXCEL方法总结 MVC导出数据到EXCEL的方法有很多种,常见的是: 1.采用EXCEL COM组件来动态生成XLS文件并保存到服务器上,然后转到该文件存放路径即可: 优点:可设置丰富的EXC ...

  7. 用javascript得到客户端IP的新方法

    javascript得到客户端IP的新方法 很久以来,我都是经过http://fw.qq.com/ipaddress来得到客户端用户的IP,这个方法简单.快速.实用 . 我们调用它的写法是: < ...

  8. spring AOP Bean添加新方法

    目的:为studentAdditionalDetails中添加Student的showDetails()和ExtraShowDetails()两个方法 spring  中AOP能够为现有的方法添加额外 ...

  9. 看es6 字符串新方法有感

    'x'.repeat(3) // "xxx" 'hello'.repeat(2) // "hellohello" 'na'.repeat(0) // " ...

随机推荐

  1. MSSQL取得或删除重复数据

    1.取得不重复的数据 select * from Persons where Id in ( SELECT MAX(Id) AS Expr1 FROM Persons GROUP BY Name, G ...

  2. Python的网络编程[1] -> FTP 协议[1] -> 使用 pyftplib 建立 FTP 服务器

    使用 pyftplib 建立 FTP 服务器 pyftplib 主要用于建立 FTP Server,与 ftplib 建立的 Client 进行通信. 快速导航 1. 模块信息 2. 建立 FTP 服 ...

  3. 谷歌浏览器cookies管理插件:EditThisCookie

    目前大多数网站的登录程序或者是其他保存用户信息到本地浏览器的方式都是使用cookies的方式,而cookies虽然可以为用户的一些操作带来便捷,比如可以记住用户的密码或者用户的选择历史,在下一次操作的 ...

  4. Codeforces 757 E Bash Plays with Functions

    Discription Bash got tired on his journey to become the greatest Pokemon master. So he decides to ta ...

  5. [xsy2724]Tree

    题意:给一棵树,找出$k$个点$A_{1\cdots k}$以最小化$\begin{align*}\sum\limits_{i=1}^{k-1}dis_{A_i,A_{i+1}}\end{align* ...

  6. 【bzoj4808】【马】二分图最大点独立集+简单感性证明

    (上不了p站我要死了,侵权度娘背锅) Description 众所周知,马后炮是中国象棋中很厉害的一招必杀技."马走日字".本来,如果在要去的方向有别的棋子挡住(俗称"蹩 ...

  7. NOI2014 部分题解

    感觉NOI2014的一些题目也是比较好做的... 但是笔者往往有思路却没有想清楚就开始搞了...这样还是不太好.. Day1 T1 起床困难综合征  (我感觉这题应该叫综合征不是综合症...)   a ...

  8. Codeforces Round #228 (Div. 1) 388B Fox and Minimal path

    链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...

  9. 【Linux】CentOS7上rpm命令批量卸载删除模糊rpm包名

    例如,我要删除如下文件名匹配上wine的所有文件

  10. android在Service中弹出Dialog对话框,即全局性对话框

    先说具体做法,原因在其后给出: 写好Alter功能块后,在alter.show()语句前加入: alert.getWindow().setType(WindowManager.LayoutParams ...