您的位置:首页 > 其它

视图控制器中之间切换的几种方式 by 李梦珂

2015-11-22 17:35 435 查看
**

1.模态视图

**

-(void)presentModel

{

RootViewController *rootview = [[RootViewController alloc]init];

rootview.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:rootview animated:YES completion:^{
NSLog(@"call back");
}];


}

2,UITabBarController实现并列画面跳转

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

UIViewController *vc1 = [[UIViewController alloc]init];
vc1.title = @"消息";
vc1.view.backgroundColor = [UIColor redColor];
UIViewController *vc2 = [[UIViewController alloc]init];
vc2.title = @"设置";
vc2.view.backgroundColor = [UIColor orangeColor];
UIViewController *vc3 = [[UIViewController alloc]init];
vc3.title = @"主页";
vc3.view.backgroundColor = [UIColor yellowColor];
UIViewController *vc4 = [[UIViewController alloc]init];
vc4.title = @"微博";
vc4.view.backgroundColor = [UIColor greenColor];
UIViewController *vc5 = [[UIViewController alloc]init];
vc5.title = @"图片";
vc5.view.backgroundColor = [UIColor blueColor];

NSArray *controller = @[vc1,vc2,vc3,vc4,vc5];
UITabBarController *tabbar = [[UITabBarController alloc]init];
tabbar.viewControllers = controller;




**

3,UINavigationController实现多层画面跳转,在导航控制器中,载入有层级关系的界面

**

-(void)pushNavigation

{

SecondViewController *controller2 = [[SecondViewController alloc]init];

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

}

-(void)index

{

UIViewController *second = [[self.navigationController viewControllers]objectAtIndex:1];

[self.navigationController popToViewController:second animated:YES];

}

注:UInavigationController中各视图之间有层级关系,用栈的模式来管理视图控制器,而UITabBarController中各视图之间是并列关系,无层级之分。

两者混合使用时最好将UINavigationController加到UITabBarController上!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: