53 lines
2.6 KiB
Swift
53 lines
2.6 KiB
Swift
//
|
||
// MPPositive_NavigationController.swift
|
||
// MusicPlayer
|
||
//
|
||
// Created by Mr.Zhou on 2024/4/19.
|
||
//
|
||
|
||
import UIKit
|
||
///b面导航栏
|
||
class MPPositive_NavigationController: MP_NavigationController {
|
||
|
||
//重写pushViewController
|
||
//每一次push都会执行这个方法,push之前设置viewController的hidesBottomBarWhenPushed
|
||
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
|
||
viewController.hidesBottomBarWhenPushed = true
|
||
NotificationCenter.notificationKey.post(notificationName: .positive_nav_push)
|
||
super.pushViewController(viewController, animated: true)
|
||
viewController.hidesBottomBarWhenPushed = false
|
||
}
|
||
//重写popViewController
|
||
//每一次对viewController进行push的时候,会把viewController放入一个栈中
|
||
//每一次对viewController进行pop的时候,会把viewController从栈中移除
|
||
override func popViewController(animated: Bool) -> UIViewController? {
|
||
guard self.children.count != 1 else {
|
||
//特殊情况,当用户连续触发pop事件时进行容错处理
|
||
return super.popViewController(animated: true)
|
||
}
|
||
guard self.children.count == 2 else {
|
||
//如果viewController栈中存在的ViewController的个数超过两个,对要返回到的上一级的界面设置hidesBottomBarWhenPushed = true
|
||
//把tabbar进行隐藏
|
||
let count = self.children.count-2
|
||
let controller = self.children[count]
|
||
controller.hidesBottomBarWhenPushed = true
|
||
NotificationCenter.notificationKey.post(notificationName: .positive_nav_push)
|
||
return super.popViewController(animated: true)
|
||
}
|
||
//如果viewController栈中存在的ViewController的个数为两个,再返回上一级界面就是根界面了
|
||
//那么要对tabbar进行显示
|
||
let controller:UIViewController = self.children[0]
|
||
controller.hidesBottomBarWhenPushed = false
|
||
NotificationCenter.notificationKey.post(notificationName: .positive_nav_pop)
|
||
return super.popViewController(animated: true)
|
||
}
|
||
override func popToRootViewController(animated: Bool) -> [UIViewController]? {
|
||
//如果viewController栈中存在的ViewController的个数为两个,再返回上一级界面就是根界面了
|
||
//那么要对tabbar进行显示
|
||
let controller:UIViewController = self.children[0]
|
||
controller.hidesBottomBarWhenPushed = false
|
||
NotificationCenter.notificationKey.post(notificationName: .positive_nav_pop)
|
||
return super.popToRootViewController(animated: animated)
|
||
}
|
||
}
|