我的导航栏上有largeTitle,可以正确显示。
当我将设备方向更改为横向并重新更改为纵向时,它将变为常规而不是largeTitle。
这是一个标签栏控制器。当我将标签页切换到gif下方的“日历”中时,该视图会重新加载并正确显示
在我的标签栏控制器中,我已经添加了它,但并不能帮助我重新调整导航栏中的largeTitle
override func viewWillTransition(to size: CGSize, with coordinator:
UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape {
//do something
} else {
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always
}
}
如果我在我的tabviewcontroller中添加以上代码,它甚至不会调用。它从我的标签栏控制器中调用,但没有将标题更新为大
我很感动。请让我知道我该如何解决
答案 0 :(得分:0)
您可以在更改设备方向时将导航栏高度重置为默认高度(为简单起见,在这里我重置了整个导航栏框架):
class ViewController: UIViewController {
lazy var navigationControllerLargeTitleFrame: CGRect = {
let navigationController = UINavigationController()
navigationController.navigationBar.prefersLargeTitles = true
return navigationController.navigationBar.frame
}()
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChangeNotification), name: UIDevice.orientationDidChangeNotification, object: nil)
}
@objc func orientationDidChangeNotification(_ notification: NSNotification) {
if UIDevice.current.orientation == .portrait {
navigationController?.navigationBar.frame = navigationControllerLargeTitleFrame
}
}
}