-1

I have a problem within my app where a LargeTitle is set on View1, however when I launch View2 the title snaps back to small. As a result when the back button is pressed on View2, View1 launches with the LargeTitle snapping from small to large.

The code I have used to create LargeTitle is 'navigationItem.largeTitleDisplayMode = .always' which is within the ViewWillAppear.

View1 -

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

        navigationItem.largeTitleDisplayMode = .always

if #available(iOS 12.0, *) {
           
            self.navigationController?.navigationBar.barTintColor = UIColor(named: "#222222")
               
            self.navigationController?.navigationBar.isTranslucent = true;

            self.navigationController?.navigationBar.tintColor = UIColor.white
                
            navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
            
        }

'

View2 -

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

    self.navigationController?.setToolbarHidden(true, animated: false)
    
    navigationController?.navigationBar.prefersLargeTitles = false

    if #available(iOS 13.0, *) {
        UIApplication.shared.statusBarStyle = .darkContent
    } 
    
    if #available(iOS 12.0, *) {
        self.navigationController?.navigationBar.barTintColor = UIColor.white
            self.navigationController?.navigationBar.isTranslucent = false;
            self.navigationController?.navigationBar.tintColor = UIColor.black
            navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]

    }
    
    self.navigationItem.titleView = setTitle(title: name, titleColor: UIColor.black, titleSize: 14, subtitle: category, subtitleColor: UIColor.gray, subtitleSize: 12, view: self.view)'

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

    navigationController?.navigationBar.prefersLargeTitles = true
    
    navigationController?.navigationItem.largeTitleDisplayMode = .always
    
    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

    self.navigationController?.navigationBar.isTranslucent = true;

}'

This is the code I have used associated with title text for both View's. The storyboard is nested in a NavigationController, so this may have something to do with it.

NOTE - I have not set LargeTitle via Storyboard, however when doing so this does not fix the issue.

Here is a video snippet of the problem. :

Snapping LargeTitle:-

enter image description here

1 Answers1

0

I think the issue is that you need to restore navigationItem.largeTitleDisplayMode = .always' in the second view when it's about to disappear

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

       navigationItem.largeTitleDisplayMode = .always'
    }