How to Hide Tab Bar Controller?

后端 未结 10 1649
猫巷女王i
猫巷女王i 2020-12-05 00:43

How to Hide Tab Bar Controller ? I want to hide the Tab Bar controller with double tap on UIImageView.

相关标签:
10条回答
  • 2020-12-05 01:01

    Objective-C

    [self.tabBarController.tabBar setHidden:YES];
    

    Swift 3

    self.tabBarController?.tabBar.isHidden = true
    

    Swift 2

    self.tabBarController?.tabBar.hidden = true
    
    0 讨论(0)
  • 2020-12-05 01:03

    Use Tap Gesture Recognizer to detect double taps on a UIImageView. Then invoke a method on detecting the double double tap. Add the following line of code in that method.

    self.tabBarController.tabBar.hidden=YES;
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-05 01:04

    Try this code:

    [self.tabBarController.tabBar setHidden:YES];
    

    where tabbarcontroller is needed to be defined...

    EDIT

    AppDelegateFileName *appDelegate = (AppDelegateFileName *) [[UIApplication sharedApplication] delegate];
    [appDelegate.tabbarController.tabBar setHidden:YES];
    

    before doing this make sure that you create a @property declaration of tabbarController in appDelegate .h file.

    0 讨论(0)
  • 2020-12-05 01:14

    UIViewController has a property

    @property(nonatomic, readonly, retain) UITabBarController *tabBarController
    

    which you can set:

    self.tabBarController.tabBar.hidden = YES;
    
    0 讨论(0)
  • 2020-12-05 01:17

    Objective-C

    [self.tabBarController.tabBar setHidden:YES];

    Objective-C 2.0

    self.tabBarController.tabBar.hidden = YES;

    Swift before iOS 9

    tabBarController?.tabBar.hidden = true

    Swift iOS 9 and above

    tabBarController?.tabBar.isHidden = true

    Extra trick with Swift 5 and above: if you would like to change the hidden property then toggle it

    if let t = tabBarController?.tabBar {
        t.isHidden = t.!isHidden
    }
    // is equal to 
    tabBarController?.tabBar.isHidden.toggle()
    
    0 讨论(0)
  • 2020-12-05 01:17

    Swift Solution for multiple root view controllers

    If you or someone would need to hide the tab bar inside a custom controller, for an app that uses multiple rootViewController try something like this:

    //instantiate appDelegate in your controller first
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    
    //then just hide the tab bar as following
    appDelegate.window?.rootViewController?.tabBarController?.tabBar.isHidden = true
    
    0 讨论(0)
提交回复
热议问题