Hiding the tabbar and removing the space

前端 未结 14 1688
生来不讨喜
生来不讨喜 2020-11-30 00:10

Is there a way to hide tabbar and remove that space left (around 50px) ?

I tried

self.tabBarController?.tabBar.hidden = true
self.extendedLayoutIncl         


        
相关标签:
14条回答
  • 2020-11-30 01:06

    Sometimes that easiest way is just to add a view that uses the UIScreen bounds.

    let whiteView = UIView()
        whiteView.backgroundColor = .white
        view.addSubview(whiteView)
        whiteView.translatesAutoresizingMaskIntoConstraints = false
        whiteView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        whiteView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        whiteView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        whiteView.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height).isActive = true
    

    Cause sometimes the view edges extends beyond the nav bar giving you new problems if you extend the view layout.

    0 讨论(0)
  • 2020-11-30 01:08

    Swift 3:

    extension UITabBarController {
        func setTabBarVisible(visible:Bool, duration: TimeInterval, animated:Bool) {
            if (tabBarIsVisible() == visible) { return }
            let frame = self.tabBar.frame
            let height = frame.size.height
            let offsetY = (visible ? -height : height)
    
            // animation
            UIViewPropertyAnimator(duration: duration, curve: .linear) {
                self.tabBar.frame.offsetBy(dx:0, dy:offsetY)
                self.view.frame = CGRect(x:0,y:0,width: self.view.frame.width, height: self.view.frame.height + offsetY)
                self.view.setNeedsDisplay()
                self.view.layoutIfNeeded()
            }.startAnimation()
        }
    
        func tabBarIsVisible() ->Bool {
            return self.tabBar.frame.origin.y < UIScreen.main.bounds.height
        }
    }
    

    To use (if for example self is a UITabBarController):

    self.setTabBarVisible(visible: false, duration: 0.3, animated: true)
    

    Swift 2.x:

    extension UITabBarController {
        func setTabBarVisible(visible:Bool, duration: NSTimeInterval, animated:Bool) {
            if (tabBarIsVisible() == visible) { return }
            let frame = self.tabBar.frame
            let height = frame.size.height
            let offsetY = (visible ? -height : height)
    
            // animation
            UIView.animateWithDuration(animated ? duration : 0.0) {
                self.tabBar.frame = CGRectOffset(frame, 0, offsetY)
                self.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height + offsetY)
                self.view.setNeedsDisplay()
                self.view.layoutIfNeeded()
            }
        }
    
        func tabBarIsVisible() ->Bool {
            return self.tabBar.frame.origin.y < UIScreen.mainScreen().bounds.height
        }
    }
    

    To use:

    self.tabBarController?.setTabBarVisible(visible: false, duration: 0.3, animated: true)
    
    0 讨论(0)
  • 2020-11-30 01:13

    I was facing the same issue and root cause was BOTTOM CONSTRAINT

    Make sure you set the bottom constraint of your bottom most view in the main view hierarchy with SUPERVIEW, NOT "SAFE AREA"

    Hope this helps someone..

    0 讨论(0)
  • 2020-11-30 01:13

    Yes. You can hide your tab bar when you push to view controller. You can show tab bar in your home. You can hide your tab bar when you push to next View controller.

    See the Hide Botton Bar on Push following image and set in all viewcontrollers where you dont want tab bar.

    Hope it helps..

    0 讨论(0)
  • 2020-11-30 01:16

    Programmatically, add this to the next view controller for swift 4.

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        tabBarController?.tabBar.isHidden = true
        edgesForExtendedLayout = UIRectEdge.bottom
        extendedLayoutIncludesOpaqueBars = true
    }
    

    And add a background color

    0 讨论(0)
  • 2020-11-30 01:17

    If you're still seeing a black stripe under your hidden tab bar, have you tried to select Extend Edges Under Opaque Bars here?

    Make also sure that Under Bottom Bars is still selected. Hope it helps!

    0 讨论(0)
提交回复
热议问题