I use an UITabBarController which has more than 5 items. I customized moreNavigationController to remove navigation bar and making it dark. But when I rotate the device to landscape and come to the portrait again it shows the navigation bar at the top and its white again. This only happens when I select a ViewController from moreNavigationController and rotate it.
Here is my code :
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
}
}
}
I was achieved to do so using the code below. I used viewWillTransition before but the key part is running customization code after the transition.
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)
}
}