自定义 moreNavigationController 旋转后重置

Customized moreNavigationController resets after rotation

我使用的 UITabBarController 有超过 5 个项目。我定制了 moreNavigationController 以删除导航栏并使其变暗。但是当我将设备旋转到横向并再次进入纵向时,它会在顶部显示导航栏并再次显示为白色。只有当我 select 来自 moreNavigationController 的 ViewController 并旋转它时才会发生这种情况。

这是我的代码:

class CustomTabBar: UITabBarController,UITabBarControllerDelegate {
override func viewDidLoad() {
    delegate = self
    self.customizableViewControllers = []
    self.moreNavigationController.navigationBar.isHidden = true
}

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    // style all the tab bar windows and the More tab bar tableview
    if viewController == moreNavigationController,
        let moreTableView = moreNavigationController.topViewController?.view as? UITableView {
        moreNavigationController.setNavigationBarHidden(true, animated: false)
        let dark = UIColor(hexString: "#1F242A")
       moreTableView.backgroundColor = dark
        moreTableView.tintColor = .white
        moreTableView.visibleCells.forEach{ cell in
            cell.backgroundColor = dark
            cell.textLabel?.textColor = .white
        }
    }
}

我是使用下面的代码实现的。我之前使用过 viewWillTransition,但关键部分是 运行 自定义代码 转换之后。

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    coordinator.animate(alongsideTransition: nil) { _ in
        self.moreNavigationController.setNavigationBarHidden(true, animated: false)
    }
}