您的位置:首页 > 其它

视图ViewController之间的切换及动画设置

2014-10-08 10:21 639 查看
视图ViewController之间的切换方式有很多,其中最常用的有以下三种:导航UINavigationController,模态视
presentModalViewController,控制栏UITabBarController

一、导航控制器UINavigationController这种切换主要适用于有层次逻辑性的ViewController之间

//切换一、NavigationController的push

[self.navigationController
pushViewController:publishVC animated:YES];

[self
setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
说明:
UIViewController自身之间的调用:[self presentModalViewController:UIViewController animated:YES];

对应的返回操作函数:[self dismissModalViewControllerAnimated:YES];这里的self代表的是UIViewController自己。

其可设置四种动画模式:

case 0:

[ctrl setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; //底部向上 默认的动画方式

break;

case 1:

[ctrl setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; //渐变

break;

case 2:

[ctrl setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; //翻转

break;

case 3:

[ctrl setModalTransitionStyle:UIModalTransitionStylePartialCurl]; //翻半页

break;

default:

[ctrl setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; //底部向上 默认的动画方式

break;

二、模态视图切换presentModalViewController,对应的返回函数:dismissModalViewController

他的切换动画可以有一下两种方法设置:

//切换二、presentVC的ModalTransiionStyle和ModalPresentationStyle切换

[publishVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

[publishVC setModalPresentationStyle:UIModalPresentationCurrentContext];

[self
presentViewController:publishVC animated:YES
completion:nil];

//切换三、presentVC的自定义

CATransition * animation = [CATransition
animation];
[animation
setDuration:0.5];

[animation setSubtype:kCATransitionFromLeft];
[animation
setType:kCATransitionPush];

[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[publishVC.view
layer]addAnimation:animation
forKey:@"SwitchToView" ];

[self
presentViewController:publishVC animated:NO
completion:nil];

Controller调用了返回函数,如dismiss,pop等等,那么就会被清理掉。
备注:如果Controller或view中有线程或者定时器之类的动画操作如果没有结束那么这个Controller或view就会出现内存泄露了。

三、UITabBarContrller其也是继承于UIViewController,主要是做具有并行逻辑特点的ViewController之间的切换。

UITabBarContrller对象有一个属性selectedIndex,设置初始时默认展示的ViewController。

而当点击tabBarItem时触发切换操作 都会回调UITabBarControllerDelegate中的一个方法

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *) viewController
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐