视图ViewController之间的切换方式有很多,其中最常用的有以下三种:导航UINavigationController,模态视 presentModalViewController,控制栏UITabBarController
一、导航控制器UINavigationController这种切换主要适用于有层次逻辑性的ViewController之间
//切换一、NavigationController的push
[self.navigationController pushViewController:publishVC animated:YES];
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
说明:
二、模态视图切换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];
UITabBarContrller对象有一个属性selectedIndex,设置初始时默认展示的ViewController。
而当点击tabBarItem时触发切换操作 都会回调UITabBarControllerDelegate中的一个方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *) viewController