2

I am implementing UINavigationBar for two UIViewController: assume ControllerA and ControllerB.

ControllerA has translucent UINavigationBar with backgroundColor = .clear property.

ControllerB has prefersLargeTitles enabled property and white background.

I should push and pop from ControllerA -> ControllerB. Here the code I've implemented in controllerA life cycle methods:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        if #available(iOS 11.0, *) {
            navigationItem.largeTitleDisplayMode = .never
        }

        navigationController?.navigationBar.isTranslucent = true
        navigationController?.navigationBar.tintColor = .white
        navigationController?.navigationBar.backgroundColor = UIColor.clear

        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationController?.navigationBar.shadowImage = UIImage()
        navigationController?.navigationBar.barTintColor = .clear

        navigationController?.navigationBar.titleTextAttributes = [
            .font: FontFamily.SFProRounded.bold.font(size: 18),
            .foregroundColor: UIColor.white
        ]
    }

override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        if #available(iOS 11.0, *) {
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationItem.largeTitleDisplayMode = .always

            navigationController?.navigationBar.largeTitleTextAttributes = [
                .font: FontFamily.SFProRounded.bold.font(size: 22),
                .foregroundColor: UIColor.black
            ]
        }
        navigationController?.navigationBar.titleTextAttributes = [
            .font: FontFamily.SFProRounded.bold.font(size: 18),
            .foregroundColor: UIColor.black
        ]
        navigationController?.navigationBar.tintColor = .black
        navigationController?.navigationBar.backgroundColor = UIColor.white
        navigationController?.view.backgroundColor = UIColor.white
        navigationController?.navigationBar.barTintColor = .white
    }

Below the issues I've had on different iOS versions:

  1. Version < iOS 13

Incorrect animation and title color while tap back button for controller dismissing. Video here: https://youtu.be/1g9esUgYDK8

  1. Version == iOS 13

Large title not moving with dismissed controller during pop animation. Video here: https://youtu.be/25k3oz2_wcE

How to solve it? Thank you in advance

V.V.V
  • 235
  • 1
  • 13
  • override viewWillDisapper() in B class and again set normal navigation bar there. It help to resolve incorrect animation. – Pravin Tate Oct 15 '19 at 10:41
  • It doesn't fix the issues – V.V.V Oct 15 '19 at 10:46
  • I have faced same issue earlier but i have done above change and it resolved. – Pravin Tate Oct 15 '19 at 10:47
  • I've tried but unfortunately It didn't help.. Looks like I'm making transition between two UINavigationBar states completely wrong – V.V.V Oct 15 '19 at 10:49
  • You can try with override `viewWillDisappear` in `ControllerB` and set navigation changes back for `ControllerA`. Remove the nav settings from `viewWillAppear` and set it into `viewDidLoad`. – Farhan Amjad Oct 15 '19 at 12:44
  • @FarhanAmjad its also not working :( I suppose that problem in my code, not in methods where code is calling – V.V.V Oct 15 '19 at 13:18

1 Answers1

0

Finally I've added

if #available(iOS 11.0, *) {
    navigationItem.largeTitleDisplayMode = .always
}

in ViewDidLoad of ControllerB and

if #available(iOS 11.0, *) {
    navigationItem.largeTitleDisplayMode = .never
}

in ViewDidLoad of ControllerA and it works as I expected.

Note that you need to set prefersLargeTitles only one time, preferably when opening the application

V.V.V
  • 235
  • 1
  • 13