UITabbarController & UITabbar 学习

最后更新2016-04-06

一、 UITabbarController

  1. 给UITabbarController 设置viewControllers熟悉时候,超过五个就会有一个 moreNavigationController;

调用 UITabbarController 的 addChildViewController 可以给系统设置,但是超过五个之后就不显示了;

  1. 调用顺序

  2. UITabbarController 进去会调用三次 tabBarControllerSupportedInterfaceOrientations

    2017-04-06 09:54:10.594 UITabbarSimpleDemo[986:30480] -[ViewController         tabBarControllerSupportedInterfaceOrientations:]
    2017-04-06 09:54:10.595 UITabbarSimpleDemo[986:30480] -[ViewController tabBarControllerSupportedInterfaceOrientations:]
    2017-04-06 09:54:10.595 UITabbarSimpleDemo[986:30480] -[ViewController tabBarControllerSupportedInterfaceOrientations:]
    
    • 当你选择一个item的时候,调用堆栈为:
      • tabBar:didSelectItem:
      • tabBarController:shouldSelectViewController:
      • tabBarController:animationControllerForTransitionFromViewController:toViewController:
      • tabBarController:didSelectViewController:
    2017-04-06 09:54:17.264 UITabbarSimpleDemo[986:30480] ----[ViewController tabBar:didSelectItem:]
    

2017-04-06 09:54:17.264 UITabbarSimpleDemo[986:30480] -[ViewController tabBarController:shouldSelectViewController:]
2017-04-06 09:54:17.265 UITabbarSimpleDemo[986:30480] -[ViewController tabBarController:animationControllerForTransitionFromViewController:toViewController:]
2017-04-06 09:54:17.267 UITabbarSimpleDemo[986:30480] -[ViewController tabBarController:didSelectViewController:]
```
4. 当存在一个 More的时候,点击More里面的子控制器,不会调用UITabbarControllerDelegate 或者 UITabBarDelegate
5. 当存在一个 More的时候,点击edit, 调用 tabBar:willBeginCustomizingItems:tabBar:didBeginCustomizingItems:, 点击edit,会调用 tabBar:willEndCustomizingItems:changed: 以及 tabBar:didEndCustomizingItems:changed:

```
2017-04-06 10:04:25.463 UITabbarSimpleDemo[986:30480] ----[ViewController tabBar:willBeginCustomizingItems:]

2017-04-06 10:04:25.794 UITabbarSimpleDemo[986:30480] ----[ViewController tabBar:didBeginCustomizingItems:]
2017-04-06 10:04:27.017 UITabbarSimpleDemo[986:30480] ----[ViewController tabBar:willEndCustomizingItems:changed:]
2017-04-06 10:04:27.349 UITabbarSimpleDemo[986:30480] ----[ViewController tabBar:didEndCustomizingItems:changed:]
```

这个几个方法,都没有被调用,不知道是不是系统bug

- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED
{
    NSLog(@"%s", __func__);
}


- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED
{
    NSLog(@"%s", __func__);
}

- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed __TVOS_PROHIBITED
{
    NSLog(@"%s", __func__);
}




- (UIInterfaceOrientation)tabBarControllerPreferredInterfaceOrientationForPresentation:(UITabBarController *)tabBarController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED
{
    NSLog(@"%s", __func__);
    return UIInterfaceOrientationLandscapeRight;
}

- (nullable id <UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController
                               interactionControllerForAnimationController: (id <UIViewControllerAnimatedTransitioning>)animationController NS_AVAILABLE_IOS(7_0)
{
    NSLog(@"%s", __func__);
    return nil;
}

原文地址:https://www.cnblogs.com/gaox97329498/p/12070549.html