UITabBarController的view层级关系

本文详细解析了UITabBarController的结构和工作原理,包括如何管理content view controllers,调整Tab Bar的位置,以及如何动态修改tab项。文中还介绍了More view controller,用于处理超过五个item的情况,并提供了自定义tab顺序的方法。此外,讨论了代理方法在控制界面旋转和选择视图控制器中的作用。
摘要由CSDN通过智能技术生成

一、UITabBarController,你可以设置许多的 tab ,每一个 tab则一定要指定一个content view controller,当某个tab被点击时,继承并封装UIViewController,原理是每次点击之后先隐藏上一个记住的ViewController

UIViewController *viewController = _viewControllers[index];
if (viewController.parentViewController) {
[viewController willMoveToParentViewController:nil];
[viewController.view removeFromSuperview];
[viewController removeFromParentViewController];
}
再insert一个新的

UIViewController *viewController = _viewControllers[index];
[self addChildViewController:viewController];
viewController.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
if (self.tabBar) {
[self.view insertSubview:viewController.view belowSubview:self.tabBar];
}
else {
[self.view addSubview:viewController.view];
}
[self didMoveToParentViewController:viewController];
UITabBarController主要用来管理你提供的content view controllers,而每一个 content view controller则负责管理自己的view层级关系,通常,当你的程序想要提供一些平行(同一个等级的)的不同界面,而恰好这些界面使用到的数据是一类的,或者功能是一个系列的,那 tab bar interface 是非常有用的. 在这样的 tab bar interface界面中,UITabBarController就会选中该tab并且显示该viewController所持有的content view

你有没有发现,绝大多数的iOS程序,如果他用到了UITabBarController,那么他的外观就像上图,Tab bar默认在下面,但有时我们又希望将他显示到最上面去,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值