//
//  BsTabBarViewController.swift
//  BaiSiSMApp
//
//  Created by davidhuang on 2022/12/4.
//  Copyright © 2022 www.davidhuang.com. All rights reserved.
//

import UIKit
import ESTabBarController_swift

class YHTabBarViewController: ESTabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        handleTabBarLine()
        
        //        self.tabBar.shadowImage = UIImage()
//        self.tabBar.backgroundImage = UIImage()
        
        //        NotificationCenter.default.addObserver(self, selector: #selector(hideTabBar), name: BsConstant.BsNotification.tabBarHideNotification, object: nil)
        //
        //        NotificationCenter.default.addObserver(self, selector: #selector(showTabBar), name: BsConstant.BsNotification.tabBarShowNotification, object: nil)
    }
}

extension YHTabBarViewController {
    @objc func hideTabBar() -> Void {
        self.tabBar.isHidden = true
    }
    
    @objc func showTabBar() -> Void {
        self.tabBar.isHidden = false
    }
}

extension YHTabBarViewController {
    
    //展示tabbar上的横线
    func handleTabBarLine() -> Void {
        let rect = CGRect.init(x:0,y:0,width:KScreenWidth,height:0.5)
        let fillColor = UIColor(hex:0x888888)
        let img = UIImage.from(color: fillColor, rect: rect)
        
        UIView.transition(with:self.tabBar, duration:0.5, options: .transitionCrossDissolve) {
            if #available(iOS 13.0, *) {
                let appearance = self.tabBar.standardAppearance.copy()
                appearance.backgroundImage = UIImage()
                appearance.shadowImage = img
                self.tabBar.standardAppearance = appearance
            }
            else{
                self.tabBar.backgroundImage = UIImage()
                self.tabBar.shadowImage = img
            }
        } completion: { Bool in
        }
    }
    
}
