How to hide the tab bar?

I use this code the create a custom tabBar:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class TabBarViewController: UITabBarController {
let tabBarView = UIView()
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .systemChromeMaterialLight))
override func viewDidLoad() {
super.viewDidLoad()
generateTabBar()
setupTabBarAppearance()
}
func generateTabBar() {
viewControllers = [
generateVC(controller: UINavigationController(rootViewController: TableViewController()),
title: TableViewController().title!,
image: TableViewController().image),
generateVC(controller: UINavigationController(rootViewController: FavoritesController()),
title: FavoritesController().title!,
image: FavoritesController().image),
generateVC(controller: UINavigationController(rootViewController: SearchViewController()),
title: SearchViewController().title!,
image: SearchViewController().image)]
}
func generateVC(controller: UIViewController, title: String, image: UIImage?) -> UIViewController {
controller.tabBarItem.title = title
controller.tabBarItem.image = image
return controller
}
private func setupTabBarAppearance(){
tabBar.backgroundImage = UIImage()
tabBar.backgroundColor = .clear
tabBar.shadowImage = UIImage()
tabBar.itemWidth = (tabBar.bounds.width - 10) / 5
tabBar.itemPositioning = .centered
tabBar.tintColor = .green
tabBar.unselectedItemTintColor = .red
view.addSubview(tabBarView)
tabBarView.backgroundColor = .clear
tabBarView.translatesAutoresizingMaskIntoConstraints = false
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
let window = windowScene?.windows.first
tabBarView.frame = CGRect(x: 32, y: window!.frame.size.height - tabBar.frame.size.height - SafeArea().bottom() - 5, width: tabBar.frame.size.width - 64, height: tabBar.frame.size.height + 10)
tabBarView.layer.cornerRadius = (tabBar.frame.size.height+5)/2
view.bringSubviewToFront(tabBar)
blurView.translatesAutoresizingMaskIntoConstraints = false
blurView.clipsToBounds = true
blurView.frame = CGRect(x: 0, y:0, width: tabBarView.frame.size.width, height: tabBarView.frame.size.height)
blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2
tabBarView.addSubview(blurView)
blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2.25
tabBarView.bringSubviewToFront(blurView)
}
}
</code>
<code>class TabBarViewController: UITabBarController { let tabBarView = UIView() let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .systemChromeMaterialLight)) override func viewDidLoad() { super.viewDidLoad() generateTabBar() setupTabBarAppearance() } func generateTabBar() { viewControllers = [ generateVC(controller: UINavigationController(rootViewController: TableViewController()), title: TableViewController().title!, image: TableViewController().image), generateVC(controller: UINavigationController(rootViewController: FavoritesController()), title: FavoritesController().title!, image: FavoritesController().image), generateVC(controller: UINavigationController(rootViewController: SearchViewController()), title: SearchViewController().title!, image: SearchViewController().image)] } func generateVC(controller: UIViewController, title: String, image: UIImage?) -> UIViewController { controller.tabBarItem.title = title controller.tabBarItem.image = image return controller } private func setupTabBarAppearance(){ tabBar.backgroundImage = UIImage() tabBar.backgroundColor = .clear tabBar.shadowImage = UIImage() tabBar.itemWidth = (tabBar.bounds.width - 10) / 5 tabBar.itemPositioning = .centered tabBar.tintColor = .green tabBar.unselectedItemTintColor = .red view.addSubview(tabBarView) tabBarView.backgroundColor = .clear tabBarView.translatesAutoresizingMaskIntoConstraints = false let scenes = UIApplication.shared.connectedScenes let windowScene = scenes.first as? UIWindowScene let window = windowScene?.windows.first tabBarView.frame = CGRect(x: 32, y: window!.frame.size.height - tabBar.frame.size.height - SafeArea().bottom() - 5, width: tabBar.frame.size.width - 64, height: tabBar.frame.size.height + 10) tabBarView.layer.cornerRadius = (tabBar.frame.size.height+5)/2 view.bringSubviewToFront(tabBar) blurView.translatesAutoresizingMaskIntoConstraints = false blurView.clipsToBounds = true blurView.frame = CGRect(x: 0, y:0, width: tabBarView.frame.size.width, height: tabBarView.frame.size.height) blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2 tabBarView.addSubview(blurView) blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2.25 tabBarView.bringSubviewToFront(blurView) } } </code>
class TabBarViewController: UITabBarController {

    let tabBarView = UIView()
    let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .systemChromeMaterialLight))
    
    override func viewDidLoad() {
        super.viewDidLoad()
        generateTabBar()
        setupTabBarAppearance()
    }
    
    func generateTabBar() {
        viewControllers = [
            generateVC(controller: UINavigationController(rootViewController: TableViewController()),
                       title: TableViewController().title!,
                       image: TableViewController().image),
            generateVC(controller: UINavigationController(rootViewController: FavoritesController()),
                       title: FavoritesController().title!,
                       image: FavoritesController().image),
            generateVC(controller: UINavigationController(rootViewController: SearchViewController()),
                       title: SearchViewController().title!,
                       image: SearchViewController().image)]
    }
    
    func generateVC(controller: UIViewController, title: String, image: UIImage?) -> UIViewController {
        controller.tabBarItem.title = title
        controller.tabBarItem.image = image
        return controller
    }
    
    private func setupTabBarAppearance(){
        
        tabBar.backgroundImage = UIImage()
        tabBar.backgroundColor = .clear
        tabBar.shadowImage = UIImage()
        tabBar.itemWidth = (tabBar.bounds.width - 10) / 5
        tabBar.itemPositioning = .centered
        tabBar.tintColor = .green
        tabBar.unselectedItemTintColor = .red

        view.addSubview(tabBarView)
        
        tabBarView.backgroundColor = .clear
        tabBarView.translatesAutoresizingMaskIntoConstraints = false
        
        let scenes = UIApplication.shared.connectedScenes
        let windowScene = scenes.first as? UIWindowScene
        let window = windowScene?.windows.first
        
        tabBarView.frame = CGRect(x: 32, y: window!.frame.size.height - tabBar.frame.size.height - SafeArea().bottom() - 5, width: tabBar.frame.size.width - 64, height: tabBar.frame.size.height + 10)
        
        tabBarView.layer.cornerRadius = (tabBar.frame.size.height+5)/2
        
        view.bringSubviewToFront(tabBar)
        
        blurView.translatesAutoresizingMaskIntoConstraints = false
        blurView.clipsToBounds = true
        
        blurView.frame = CGRect(x: 0, y:0, width: tabBarView.frame.size.width, height: tabBarView.frame.size.height)
        
        blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2
        tabBarView.addSubview(blurView)
        
        blurView.layer.cornerRadius = (tabBar.frame.size.height+5)/2.25
        
        tabBarView.bringSubviewToFront(blurView)
        
    }
}

And I want to hide my tabBar when I scrolling the view. I use this code to do it:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>func changeTabBar(hidden:Bool, animated: Bool){
guard let tabBar = self.tabBarController?.tabBar else { return }
let offset = (hidden ? UIScreen.main.bounds.size.height : UIScreen.main.bounds.size.height - (tabBar.frame.size.height))
if offset == tabBar.frame.origin.y {return}
let duration:TimeInterval = (animated ? 0.5 : 0.0)
UIView.animate(withDuration: duration, animations: { tabBar.frame.origin.y = offset }, completion:nil)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
changeTabBar(hidden: true, animated: true)
} else {
changeTabBar(hidden: false, animated: true)
}
}
</code>
<code>func changeTabBar(hidden:Bool, animated: Bool){ guard let tabBar = self.tabBarController?.tabBar else { return } let offset = (hidden ? UIScreen.main.bounds.size.height : UIScreen.main.bounds.size.height - (tabBar.frame.size.height)) if offset == tabBar.frame.origin.y {return} let duration:TimeInterval = (animated ? 0.5 : 0.0) UIView.animate(withDuration: duration, animations: { tabBar.frame.origin.y = offset }, completion:nil) } func scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{ changeTabBar(hidden: true, animated: true) } else { changeTabBar(hidden: false, animated: true) } } </code>
func changeTabBar(hidden:Bool, animated: Bool){
    guard let tabBar = self.tabBarController?.tabBar else { return }
    let offset = (hidden ? UIScreen.main.bounds.size.height : UIScreen.main.bounds.size.height - (tabBar.frame.size.height))
    if offset == tabBar.frame.origin.y {return}
    let duration:TimeInterval = (animated ? 0.5 : 0.0)
    UIView.animate(withDuration: duration, animations: { tabBar.frame.origin.y = offset }, completion:nil)
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{
        changeTabBar(hidden: true, animated: true)
    } else {
        changeTabBar(hidden: false, animated: true)
    }
}

But in this case only the tab bar items are hidden and my tabBarView and blurView are not hidden.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật