Search code examples
iosanimationuiviewcontrolleruinavigationcontroller

Back button animation with large title jumps


We have two UIViewController with an UINavigationController.

In the first presented VC inside of viewWillAppear(_ animated: Bool) we do:

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if #available(iOS 11.0, *) {
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationController?.navigationItem.largeTitleDisplayMode = .always
        }
 ....

Inside of the second VC we deactive that behaviour with inside of viewWillAppear(_ animated: Bool):

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if #available(iOS 11.0, *) {
        navigationController?.navigationBar.prefersLargeTitles = false
    }
...

The transition animation to the second VC is smooth while tapping automatic generated back button causes the navigation controller title to create a strange jump to large title instead of the normal grow to large title animation as it does for example in the Messages App.

If i tap the tabbar icon as "back" operation, it does the right transition animation.

Any idea what could cause that issue or how i can fix it?


Solution

  • on the second view controller set the largeTitleDisplayMode to .never you won't need to set the prefersLargeTitles to false.

    To clarify things here, you've to set the largeTitleDisplayMode directly for the navigationItem of the view controller, not the navigation controller!

    self.navigationItem.largeTitleDisplayMode = .never // This fixes the issue
    self.navigationController?.navigationItem.largeTitleDisplayMode = .never // This doesn't work / Title will stay large