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. JS打印——第三方控件打印

    LODOP 官方地址:http://www.lodop.net/ 一个很好的打印控件,可以是实现纸张设置.横打竖打.打印预览.打印维护多种功能.官网的示例非常详细.能很好支持多种浏览器的打印. 在使用 ...

  2. jquery_EasyUI使用细节注意

    一.属性key不加双引号,value加双引号,对于url的value,添加‘’单引号:url的访问地址可以使用以下格式: datagrid中的url格式: var datagrid; $(functi ...

  3. Centos7更改网卡名为eth0

    1.先更该网卡配置文件设备名和网卡名参数: vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 NAME=eth0DEVICE=eth0 2.将配 ...

  4. 错误整理:容器启动报错com.sun.faces.config.WebConfiguration cannot be cast to com.sun.faces.config....

    错误集锦: 今天用Jboss部署一个web项目的时候报了个奇怪的错误(用Tomcat部署运行良好),错误信息如下:java.lang.ClassCastException: com.sun.faces ...

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

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

  6. 远程debug---远程服务器参数设置

    java  -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=25 -jar  myboot.jar 或者  java ...

  7. c++中resize这个函数怎么用

    c++中序列式容器的一个共性函数, vv.resize(int n,element)表示调整容器vv的大小为n,扩容后的每个元素的值为element,默认为0 resize()会改变容器的容量和当前元 ...

  8. 【spring Boot】2.在Myecplise上把spring Boot项目打包 war包和jar包

    ========================================================第一部分======================================== ...

  9. VUE -- 自定义控件(标签)

    首先我们在 src目录下新建一个目录 叫”component”,建一个mycomponent.vue文件,然后也让他打2句话吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...

  10. hdu4001

    参考博客http://www.cppblog.com/aswmtjdsj/archive/2011/09/04/155049.aspx 维护4根双扫描线,左右和上下.暴力枚举,复杂度O(n^2). # ...