hidesBottomBarWhenPushed为自定义视图

时间:2012-05-09 16:10:39

标签: iphone uinavigationcontroller

我想为mya app构建自定义标签栏,我遇到一个小问题:内置tabBar支持hidesBottomBarWhenPushed。有没有办法告诉我的应用我的CustomTabBar是一个底栏? 这就是我想做的事情(同一个UINavController)

                              +---------+        +---------+
                              |---------|        |---------| 
                              |         |        |         |
                              |  [btn]  |  --->  |   2nd   |
                              |         |   |    |  view   |
                              |---------|   |    |         |
          there's tabbar -->  | 1  |  2 |   |    |         |  <- no tabbar
                              +---------+   |    +---------+
                                            |
                              pushViewController:animated:

我的CustomTabBarController层次结构与原始UITabBarController的层次结构非常相似:

CustomTabBarController
  |- UINavigationController (root: FirstViewController) <- there's a button
  |- UINavigationController (root: SecondViewController)

有没有办法实现这一点?提前谢谢。

1 个答案:

答案 0 :(得分:2)

根据这个答案https://stackoverflow.com/a/4987542/263503,我在自定义标签栏控制器类中实现了以下内容:

<强> CustomTabBarController.h

@interface CustomTabBarController : UITabBarController <UINavigationControllerDelegate>

<强> CustomTabBarController.m

- (void)navigationController:(UINavigationController *)navigationController
  willShowViewController:(UIViewController *)viewController
                animated:(BOOL)animated
{
    if (viewController.hidesBottomBarWhenPushed) {
        self.tabBarImage.hidden = YES;
    } else if ([viewController isKindOfClass:[CustomViewController class]]) {
        self.tabBarImage.hidden = NO;
    }
}

此外,我还需要知道何时再次显示标签栏的自定义图像。所以我检查添加到tabBar.viewcontrollers

的viewcontroller的类

希望这会有所帮助。

相关问题