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. JSON的相关内容

    包括: JSON概述, JSON语法规则, 使用JSON(JSON对象,JSON数组,JSON文档与对象的转换) JSON应用 额外内容(PHP输出JSON数据,解析JSON字符串,客户端如何使用服务 ...

  2. hdu 5067(暴力搜索)

    Harry And Dig Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. sql:将秒转化成时分秒格式

    DECLARE @a int=20000 SELECT CONVERT(VARCHAR(10),@a/60)+'分'+CONVERT(VARCHAR(10),@a%60)+'秒' --333分20秒 ...

  4. 51nod 1095 Anigram单词【hash/map/排序/字典树】

    1095 Anigram单词 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b ...

  5. Python与数据库[1] -> 数据库接口/DB-API[0] -> 通用标准

    数据库接口 / DB-API 在Python中,数据库是通过适配器(Adaptor)来连接访问数据库的,适配器通常与数据库客户端接口(通常为C语言编写)想连接,而不同的适配器都会尽量满足相同的DB-A ...

  6. ThinkPHP中实例化对象M()和D()的区别

    ThinkPHP中实例化对象M()和D()的区别 ThinkPHP中实例化对象M()和D()的区别?ThinkPHP如何实例化对象?在实例化的过程中,经常使用D方法和M方法,这两个方法的区别在于M方法 ...

  7. Ubuntu 16.04将系统时间写入到硬件时间BIOS

    说明:在Ubuntu中为了和Windows保持一致,会将系统时间设置成CST的,所以下面的说法是设置成UTC的问题是由于所在的环境不一致导致的,本章只讨论如何设置时间到BIOS,不做时区分析,下面忽略 ...

  8. Nand flash uboot 命令详解

    转:http://blog.chinaunix.net/uid-14833587-id-76513.html nand info & nand device 显示flash的信息: DM365 ...

  9. 【Linux】CentOS7上安装JDK 和卸载 JDK 【rpm命令的使用】

    之前有过一篇在CentOS7上安装JDK的文章:http://www.cnblogs.com/sxdcgaq8080/p/7492426.html 在这里又说一次,是要使用rpm命令安装JDK的rpm ...

  10. Incorrect key file for table '/tmp/#sql_46fd_0.MYI'; try to repair it

    当查询数量很大时,(我的数据库70万数据),会导致这个错误,这是MYSQL中的一个bug. 解决方法 :   1. 修复表 check table tablename. 查看表的状态.如果有错误,则需 ...