如何解决自定义moreNavigationController旋转后重置
我使用的UITabBarController具有超过5个项目。我自定义了moreNavigationController来删除导航栏并使它变暗。但是,当我将设备旋转到横向并再次进入肖像时,它会在顶部显示导航栏,并再次显示其白色。仅当我从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)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。