简体   繁体   English

如果我输入一个给定的ViewController,如何删除TabBar

[英]How can I remove TabBar if I enter one given ViewController

Setting: 设置:

Assume I have 2 TableViewControllers(All in their own NavigationControllers), which contain TypeA&B items correspondingly. 假设我有2个TableViewControllers(All在他们自己的NavigationControllers中),它们相应地包含TypeA和B项。

In any TableView, If I tap "+" button, it will segue to a Add[?]ItemViewController("?" is The Type of Item: A or B).So normally, even if I already in the AddView, I can also switch to another View By tapping Tab Bar Icon, right? 在任何TableView中,如果我点击“+”按钮,它将转换为Add [?] ItemViewController(“?”是项目类型:A或B)。通常,即使我已经在AddView中,我也可以也可以通过点击标签栏图标切换到另一个视图,对吧?

SO How can I inhibit user to switch if they already entered one AddView? 如果他们已经进入一个AddView,我如何禁止用户切换?

Use the Swift code? 使用Swift代码? or just change the storyboard structure? 或者只是改变故事板结构?

Here is the Structure of Main.storyboard: 这是Main.storyboard的结构:

在此输入图像描述

We've done exactly the same in our application. 我们在应用程序中完成了相同的操作。 To hide the default TabBar, simply override the hidesBottomBarWhenPushed method in your parent view controller (or in every view controller in your App) 要隐藏默认TabBar,只需覆盖父视图控制器(或应用程序中的每个视图控制器)中的hidesBottomBarWhenPushed方法

#pragma mark - Overriden UIViewController methods
- (BOOL)hidesBottomBarWhenPushed {
    return YES;
}

在此输入图像描述

another Solution 另一种方案

You can also Hide Tab bar 您还可以隐藏标签栏

// pass a param to describe the state change, an animated flag and a completion block matching UIView animations completion 
- (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)(BOOL))completion {

    // bail if the current state matches the desired state
    if ([self tabBarIsVisible] == visible) return;

    // get a frame calculation ready
    CGRect frame = self.tabBarController.tabBar.frame;
    CGFloat height = frame.size.height;
    CGFloat offsetY = (visible)? -height : height;

    // zero duration means no animation
    CGFloat duration = (animated)? 0.3 : 0.0;

    [UIView animateWithDuration:duration animations:^{
        self.tabBarController.tabBar.frame = CGRectOffset(frame, 0, offsetY);
    } completion:completion];
}

// know the current state
- (BOOL)tabBarIsVisible {
    return self.tabBarController.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame);
}

// illustration of a call to toggle current state
- (IBAction)pressedButton:(id)sender {

    [self setTabBarVisible:![self tabBarIsVisible] animated:YES completion:^(BOOL finished) {
        NSLog(@"finished");
    }];
}

another Solution 另一种方案

You can set the UIViewController.hidesBottomBarWhenPushed instead: 您可以设置UIViewController.hidesBottomBarWhenPushed:

DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在appdelegate swift中设置Tabbar时,如何设置viewcontroller的rootview? - How can I set rootview of a viewcontroller when I have set Tabbar in appdelegate swift? 如何在另一个ViewController之上显示一个ViewController? - How can I present one ViewController on top of another ViewController? 如何使用给定的根ViewController和初始ViewController实例化情节提要? - How do I instantiate a storyboard with a given root viewcontroller and initial viewcontroller? 如何将两个委托放到一个视图控制器 - How can I put two delegate to one viewcontroller 我怎么能只为一个viewController iOS做横向禁用 - how can i do landscape disable for just one viewController iOS 如何在一个 ViewController 中使用两个 Webview? - how can I use two Webviews in one ViewController? 我如何在 swift 3 的一个视图控制器中填充两个不同的表视图 - How i can fill two different tableview in one viewcontroller in swift 3 如何使用一个ViewController文件加载景观xib? - How can I load a landscape xib using one ViewController file? 我该如何修复ViewController? - How can I fix ViewController? 从一个ViewController获得图像,如何在另一个ViewController上显示它 - Got an image from one ViewController, how can I display it on the other ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM