//
//  RootnaVC.swift
//  Funny_sounds
//
//  Created by 忆海16 on 2024/8/14.
//

import UIKit

class RootnaVC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setbackBtn()
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if self.viewControllers.count <= 1 {
            let viewController = RootVC()
            viewController.hidesBottomBarWhenPushed = true
            tabBarController?.tabBar.isHidden = true
            return false
        }
        setbackBtn()
        return true
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            //            setBackItmer()/
            viewController.hidesBottomBarWhenPushed = true
            tabBarController?.tabBar.isHidden = true
        }
        setbackBtn()
        super.pushViewController(viewController, animated: animated)
        
    }
    func setbackBtn(){
        
        let backButton = UIButton(type: .custom)
        
        
        backButton.setBackgroundImage(#imageLiteral(resourceName: "back"), for: .normal)
        
        backButton.addTarget(self, action: #selector(back), for: .touchUpInside)
        
        
        let backView = UIBarButtonItem(customView: backButton)
        
        let barButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        barButtonItem.width = -5
        
        
        navigationItem.leftBarButtonItems = [barButtonItem, backView]
        
    }
    
    @objc func back(){
        navigationController?.popViewController(animated: true)
        
    }

}
