It seems that I can't set navigationItem.largeTitleDisplayMode = .always
unless I also set navigationBar.prefersLargeTitles = true
? Is this intended behavior?
I'm having a really hard time believing apple would force me to manually set largeTitleDisplayMode = .never
on every screen in the navigation controller, even ones I don't control, in order to get just a single screen to show with large titles.
You can try controlling this via UINavigationControllerDelegate.willShow calls like this.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.delegate = self
}
}
// Assumption: ViewController is rootViewController for the UINavigationController
extension ViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
let isRootVC = (viewController === self)
viewController.navigationItem.largeTitleDisplayMode = isRootVC ? .always : .never
}
}
The other option would be to do this same management on viewWillAppear(_:)
& viewWillDisappear(_:)
calls for the rootViewController instance in your navigation stack.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.