How to Hide Tab Bar Controller?

2019-01-13 16:05发布

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

9条回答
再贱就再见
2楼-- · 2019-01-13 16:46

Swift 2.1:

self.tabBarController!.tabBar.hidden = true
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-13 16:47

Use the code below to hide/show tab bar controller in animated style.
hiddenTabBar is a BOOL variable.

- (void) hidetabbar {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.0];

    for(UIView *view in objtabbar.view.subviews)
    {

        if([view isKindOfClass:[UITabBar class]])
        {

            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (hiddenTabBar) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }

        }
    }

    [UIView commitAnimations];

    hiddenTabBar = !hiddenTabBar;
}
查看更多
forever°为你锁心
4楼-- · 2019-01-13 16:49

Use TapGesture 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.

查看更多
男人必须洒脱
5楼-- · 2019-01-13 16:52

Try this when you push the view to the new view:

self.tabbarconroller.tabbar.hidden = YES;
查看更多
劳资没心,怎么记你
6楼-- · 2019-01-13 16:54

If you want to change with animation you could use this code:

extension UITabBarController {

func set(visible: Bool, animated: Bool, completion: ((Bool)->Void)? = nil ) {

    guard isVisible() != visible else {
        completion?(true)
        return
    }

    let offsetY = tabBar.frame.size.height
    let duration = (animated ? 0.3 : 0.0)

    let beginTransform:CGAffineTransform
    let endTransform:CGAffineTransform

    if visible {
        beginTransform = CGAffineTransform(translationX: 0, y: offsetY)
        endTransform = CGAffineTransform.identity
    } else {
        beginTransform = CGAffineTransform.identity
        endTransform = CGAffineTransform(translationX: 0, y: offsetY)
    }

    tabBar.transform = beginTransform
    if visible {
        tabBar.isHidden = false
    }

    UIView.animate(withDuration: duration, animations: {
        self.tabBar.transform = endTransform
    }, completion: { compete in
        completion?(compete)
        if !visible {
            self.tabBar.isHidden = true
        }
    })
}

func isVisible() -> Bool {
    return !tabBar.isHidden
}
}

More you can read in https://stackoverflow.com/a/50101262/1797194

查看更多
Lonely孤独者°
7楼-- · 2019-01-13 16:55

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.

查看更多
登录 后发表回答