Hiding the tabbar and removing the space

前端 未结 14 1705
生来不讨喜
生来不讨喜 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: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)
    

提交回复
热议问题