// // MPPositive_TabBarController.swift // MusicPlayer // // Created by Mr.Zhou on 2024/4/19. // import UIKit ///b面tabBar控制器 class MPPositive_TabBarController: UITabBarController { //自定义tabBar private lazy var customTabBar:MPPositive_CustomTabBar = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 72*width)) private lazy var bottomView:MPPositive_BottomShowView = .init(frame: .init(x: 0, y: 0, width: 351, height: 82)) override func viewDidLoad() { super.viewDidLoad() self.setValue(customTabBar, forKey: "tabBar") //创建标签子控制器 let homeVC = MPPositive_NavigationController(rootViewController: MPPositive_HomeViewController()) let searchVC = MPPositive_NavigationController(rootViewController: MPPositive_SearchViewController()) let libraryVC = MPPositive_NavigationController(rootViewController: MPPositive_LibraryViewController()) viewControllers = [homeVC,searchVC,libraryVC] //禁止系统tabBaritem触发 tabBar.items?.forEach({ item in item.isEnabled = false }) tabBar.barTintColor = .clear UITabBar.appearance().backgroundColor = .clear tabBar.shadowImage = UIImage() tabBar.backgroundImage = UIImage() //添加底部播放View view.addSubview(bottomView) //将展示View设置在主窗口下方之外,避免用户察觉 bottomView.snp.makeConstraints { make in make.centerX.equalToSuperview() make.bottom.equalToSuperview().offset(82*width) make.width.equalTo(351*width) make.height.equalTo(82*width) } addNotification() } //监听通知 private func addNotification() { //监听标签切换 NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchAction(_:)), notificationName: .switch_tabBarItem) } deinit { //移除所有监听 NotificationCenter.default.removeObserver(self) } } //MARK: - 通知处理 extension MPPositive_TabBarController { //切换事件 @objc private func switchAction(_ sender:Notification) { let tag = sender.object as! Int selectedIndex = tag } //弹出player控制器 @objc private func pupPlayerAction(_ sender:Notification) { } }