标签栏不隐藏使用 DDMenuController(Fb 像滑动菜单)

Posted

技术标签:

【中文标题】标签栏不隐藏使用 DDMenuController(Fb 像滑动菜单)【英文标题】:Tab Bar not hiding Using DDMenuController (Fb like sliding menu) 【发布时间】:2013-06-28 11:00:18 【问题描述】:

我在过去两天遇到了这个问题,但可以找到任何解决方案。有人可以帮忙吗。这是用于 TabBar 视图控制器的代码 sn-p。

//设置标签栏

NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:5];

self.tabBarController = [[UITabBarController alloc] init];

[tabBarController

 setDelegate:self];

    UINavigationController *navController = nil;

    NSArray *vcArray = [self papulateViewControllers];

// 设置标签栏的视图控制器

-(NSArray *) papulateViewControllers
    BrowseViewController *browseVC = [[BrowseViewController alloc] initWithNibName:@"BrowseViewController" bundle:nil];

    AlbumViewController *albumVC = [[AlbumViewController alloc] initWithNibName:@"AlbumViewController" bundle:nil];


    SubmitStep1VC *submitVC = [[SubmitStep1VC  alloc] initWithNibName:@"SubmitStep1VC" bundle:nil];
    // SubmitStep1VC *submitVC = [[SubmitStep1VC  alloc] initWithNibName:@"SubmitStep1_iPhone5.xib" bundle:[NSBundle mainBundle]];

    WallViewController *wallVC = [[WallViewController  alloc] initWithNibName:@"WallViewController" bundle:nil];

    OptionVC *optionVC = [[OptionVC alloc] initWithNibName:@"OptionVC" bundle:nil];


    sliderVCRef = [[SliderVC alloc] initWithNibName:@"SliderVC" bundle:nil];

    //Navigation Controllers
    UINavigationController *browseNavController = [[UINavigationController alloc] initWithRootViewController: browseVC];
    [browseNavController setNavigationBarHidden:YES];

    UINavigationController *albumNavController = [[UINavigationController alloc] initWithRootViewController: albumVC];
    [albumNavController setNavigationBarHidden:YES];

    UINavigationController *submitNavController = [[UINavigationController alloc] initWithRootViewController: submitVC];
    [submitNavController setNavigationBarHidden:YES];

    UINavigationController *wallNavController = [[UINavigationController alloc] initWithRootViewController: wallVC];
    [wallNavController setNavigationBarHidden:YES];

    UINavigationController *optionNavController = [[UINavigationController alloc] initWithRootViewController: optionVC];
    [optionNavController setNavigationBarHidden:YES];

    DDMenuController *browseMenuController = [[DDMenuController alloc] initWithRootViewController:browseNavController];

    self.menuController = browseMenuController;
    self.menuController.leftViewController = sliderVCRef;

    DDMenuController *albumMenuController = [[DDMenuController alloc] initWithRootViewController:albumNavController];
    albumMenuController.leftViewController = sliderVCRef;

    DDMenuController *submitMenuController = [[DDMenuController alloc] initWithRootViewController:submitNavController];
    submitMenuController.leftViewController = sliderVCRef;

    DDMenuController *wallMenuController = [[DDMenuController alloc] initWithRootViewController:wallNavController];
    wallMenuController.leftViewController = sliderVCRef;

    DDMenuController *optionMenuController = [[DDMenuController alloc] initWithRootViewController:optionNavController];
    optionMenuController.leftViewController = sliderVCRef;

/// Works fine if i uncomment this line and comment next line of code (Passing Viewcontrollers is fine )

//   return [NSArray arrayWithObjects:self.menuController, albumVC, submitVC, wallVC, optionVC, nil];


////*******  issue in case i use this line   (Passing menuController creates issue of Tabbar )

    return [NSArray arrayWithObjects:self.menuController, albumMenuController, submitMenuController, wallMenuController, optionMenuController, nil];

////////////


当我尝试从 TabBarController 上方的任何视图推送到任何视图控制器时,标签栏没有隐藏。例子

grandPrizeVC.hidesBottomBarWhenPushed = YES;

它不断向我显示标签栏。 如果我尝试 appDelegate.tabbarcontroller.tabbar.hidden = YES; 它显示在新 VC 的黑色底栏上。

【问题讨论】:

我假设您正在谈论来自:github.com/devindoty/DDMenuController 的代码,在询问之前链接并提及这一点会很酷;) 那已经提到了老兄 DDMenuController .. 但是感谢一票否决:P 【参考方案1】:

您的应用正在执行您已实现的操作。您正在将滑动菜单视图控制器作为子视图控制器添加到标签栏控制器,当然,它不会隐藏。隐藏标签栏的一些建议: 1. 将标签栏控制器作为模态添加到您的 DDMenuController 2.编写一些方法来隐藏/显示标签栏(搜索隐藏标签栏会给你答案,或者你可以遍历标签栏控制器视图的子视图找到标签栏并隐藏它)。 祝你好运!

【讨论】:

【参考方案2】:

以下对我有用:

显示标签栏:

+ (void) showTabBar

    MyAppDelegate* appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication]delegate];
    UITabBar *tabBar = appDelegate.tabBarController.tabBar;
    UIView *parent = tabBar.superview; // UILayoutContainerView
    UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
    UIView *window = parent.superview;
    CGRect tabFrame = tabBar.frame;
    tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
    tabBar.frame = tabFrame;

    CGRect contentFrame = content.frame;
    contentFrame.size.height -= tabFrame.size.height;

隐藏标签栏:

+(void) hideTabBar
   MyAppDelegate* appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication]delegate];
    UITabBar *tabBar = appDelegate.tabBarController.tabBar;
    UIView *parent = tabBar.superview; // UILayoutContainerView
    UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
    UIView *window = parent.superview;

    [UIView animateWithDuration:0.01
                     animations:^
                         CGRect tabFrame = tabBar.frame;
                         tabFrame.origin.y = CGRectGetMaxY(window.bounds);
                         tabFrame.origin.y +=20;
                         tabBar.frame = tabFrame;
                         content.frame = window.bounds;
                     ];

【讨论】:

以上是关于标签栏不隐藏使用 DDMenuController(Fb 像滑动菜单)的主要内容,如果未能解决你的问题,请参考以下文章

在appdelegate类中添加tab bar viewcontroller和DDMenuController

隐藏导航栏不起作用

UISearchController 搜索栏不隐藏导航栏

页面视图 + 隐藏导航栏不起作用

导航回屏幕时隐藏的 React Native 状态栏不起作用(Android)

离子空白模板默认隐藏附件栏不起作用