CNLiveBaseTabBarViewController.swift 4.05 KB
//
//  CNLiveBaseTabbarViewController.swift
//  metaCode
//
//  Created by daojian on 2023/6/5.
//

import Foundation
import UIKit

class CNTabBar:UITabBar{
    
    override var frame: CGRect {
        
        willSet
        {
            
        }
        //我们需要在age属性发生变化后,更新一下nickName这个属性
        didSet
        {
//           print("frame = ", frame)
//           print("完成")
        }
    }
}

class CNLiveBaseTabBarViewController: UITabBarController
{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setValue(CNTabBar.init(), forKey: "tabBar")
        
        self.setUpTabBar()
        self.setupBackgroup()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("获取用户用户数据=====>\(UserInfoManager.shared.userInfo.uid)")
        
        //已经弹出过就不用再弹框了
        if ConfigManager.shared.show_update {
            CNLiveMineViewModel.requestSystemNews { result, respStatue in
                if respStatue == .success {
                    UpdataAlertView.showUpdataView(updataModel: result as! UpdateInfoModel)
                }
            }
        }
        CNLiveHomePageViewModel.requestGetHomePageTopBannerGift{[weak self] result, status in
            guard let self = self else { return }
            let giftModel = result as? CNLiveHomePageHuBiLieGiftModel
            metaAppDelegate.giftModel = giftModel
        }
    }
    // MARK: - 控制器的信息
    func setUpTabBar() {
        
        
////        let homeVC  = CNLiveNewAuthViewController.init()
        ///忽必烈
        let homeVC  = CNLiveTVHomeViewController.init()
//        let homeVC  = CNLiveAuthViewController.init()
//        let homeVC  = CNHomeWebViewController()
//        homeVC.url = URL(string: "https://wjjh5.cnlive.com/chatgpt/#/")
//        let authVC  = CNMetaCodeHomePageController.init()
        let mineVC  = CNLiveMineViewController.init()
        
        creatTabbarView(viewController: homeVC, image: "tabbar_hoem_icon_default", selectImage: "tabbar_hoem_icon_selected", title: "首页")
//        creatTabbarView(viewController: authVC, image: "tabbar_authentication_unSelect", selectImage: "tabbar_authentication", title: "认证")
        creatTabbarView(viewController: mineVC, image: "tabbar_mine_icon_default", selectImage: "tabbar_mine_icon_selected", title: "我的")

        self.tabBar.tintColor = UIColor("#0066FE")
        self.tabBar.isTranslucent = false
        self.viewControllers = [
            CNLiveBaseNavigationController(rootViewController: homeVC),
            //CNLiveBaseNavigationController(rootViewController: authVC),
            CNLiveBaseNavigationController(rootViewController: mineVC)
        ]
//        self.selectedIndex = 1
    }
    
    // MARK: - Tabar 背景图
    func setupBackgroup(){
        if #available(iOS 13.0, *) {
            let appearance: UITabBarAppearance = UITabBarAppearance.init()
            appearance.configureWithTransparentBackground()
            appearance.backgroundColor = UIColor.white
//            appearance.backgroundImage = UIImage(named: "tabbar_backgroup")
            if #available(iOS 15.0, *) {
                tabBar.scrollEdgeAppearance = appearance
            } else {
                // Fallback on earlier versions
                tabBar.standardAppearance = appearance
            }

        } else {
            tabBar.backgroundColor = .white
//            tabBar.backgroundImage = UIImage(named: "tabbar_backgroup")
        }
    }
    
    // MARK: - TabBar里面的文字图片
    func creatTabbarView(viewController:UIViewController, image:NSString, selectImage:NSString, title:NSString) {
        // alwaysOriginal 始终绘制图片原始状态,不使用Tint Color。
        viewController.tabBarItem.image = UIImage(named: image as String)?.withRenderingMode(.alwaysOriginal)
        viewController.tabBarItem.selectedImage = UIImage(named: selectImage as String)?.withRenderingMode(.alwaysOriginal)
        viewController.title = title as String
    }
}