//
//  NW_RootNAVC.swift
//  wallpaper_BProject
//
//  Created by 忆海16 on 2024/8/28.
//

import UIKit

class NW_RootNAVC: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setbackBtn()

        
    }
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if self.viewControllers.count <= 1 {
            let viewController = NW_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: "home_n"), 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)
        
    }

}
