How do I hide/show tabBar when tapped using Swift in iOS8

后端 未结 10 1058
终归单人心
终归单人心 2020-12-04 12:44

I am trying to mimic the UINavigationController\'s new hidesBarsOnTap with a tab bar. I have seen many answers to this that either point to setting the hi

10条回答
  •  甜味超标
    2020-12-04 13:21

    Code is okay but when you use presentViewController, tabBarIsVisible() is not working. To keep UITabBarController always hidden use just this part:

    extension UITabBarController {
        func setTabBarVisible(visible:Bool, animated:Bool) {
            let frame = self.tabBar.frame
            let height = frame.size.height
            let offsetY = (visible ? -height : height)
            UIView.animateWithDuration(animated ? 0.3 : 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()
            }
        }
    }
    

提交回复
热议问题