Large title to small title switch in navigation bar is not smooth iOS 13, sticky

Viewed 10822

I have a UINavigationController with default value of it's navigationBar.prefersLargeTitles = true .

I am switching that to false when I push into a new scene lets call it (DetailsViewController), by changing it into the viewWillDisappear .

override func viewWillDisappear(_ animated: Bool) {
   super.viewWillDisappear(animated)
   navigationController?.navigationBar.prefersLargeTitles = false
}

Now in DetailsViewController I am using willMove(to parent:) .

override func willMove(toParent parent: UIViewController?) {
        navigationController?.navigationBar.prefersLargeTitles = true
}

To transition back to large titles .

Observe the attached snapshots of how iOS 13 doing it with how iOS 12 is doing it, considering iOS 12 is the correct behavior.

iOS 13 :

iOS 13

iOS 12 :

iOS 12

6 Answers

What you're doing was always wrong. You should set prefersLargeTitles to true once for the navigation bar and never touch it again.

The way to change what each view controller does about large titles as it appears is that that view controller sets its own navigationItem (in its viewDidLoad) to have the desired largeTitleDisplayMode. So if the first v.c. has .always and the second has .never everything will be smooth.

Swift 5, Xcode 13:

UIViewController(1) + UINavigationController:

override func viewDidLoad() {
    super.viewDidLoad()

    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.title = "Your title here"
}

UIViewController(2 - "i.e.: detailsViewController"):

override func viewDidLoad() {
    super.viewDidLoad()
    
    navigationItem.largeTitleDisplayMode = .never
    navigationItem.title = "Your title here"
}

It works like a charm!

I had the same issue and had to place a NavigationItem on the second ViewController's storyboard. My NavigationItem was being created automatically by the segue and its prefersLargeTitle in the viewDidLoad() was not finished creating before the view appeared. Adding a NavigationItem to the storyboard fixed this issue and allowed me to set the prefersLargeTitle in the storyboard's properties menu.

In my case this problem was occurring during a segue to a view controller which is a child of a UITabBarController. Setting largeTitleDisplayMode on the child view controller was not enough to fix this bug.

I have solved the issue by adding a navigation item to the UITabBarController scene and setting largeTitleDisplayMode as .never there.

I solved this problem like this:

override func viewWillDisappear(_ animated: Bool) {
    title = ""
}

All ingenious is simple))

final class CustomHosting<Content: View>: UIHostingController<Content> {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationItem.largeTitleDisplayMode = .never
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationItem.largeTitleDisplayMode = .automatic
    }
}

I fixed same problem like this :) My problem is presenting SUI Detail Collection view from UIKit Collection, and had some jumping while navigation title changing.

Related