一、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默认在下面,但有时我们又希望将他显示到最上面去,