UINavigationController Swift View

I am presenting a loading screen where I do not want to show the navigation bar. So I am using

self.navigationController.navigationBar.hidden = true

Which does the trick and hides the navbar. But when I want to show the navigation bar, I want to animate it.

I tried using this code but the panel is not showing.

self.navigationController.setNavigationBarHidden(false, animated: true)

After running the above code, the panel is still hidden, how can I show / animate the panel?

+3


source to share


1 answer


I think your method is correct already. You just need to know where to put the code. Try the following code.

Code for ViewController 1

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBarHidden = true;
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.navigationBarHidden = true;
    }

    @IBAction func buttonTapped(sender: UIButton) {
        self.performSegueWithIdentifier("goToScreen2", sender: self)
    }
}

      

Code for ViewController 2

import UIKit

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }
}

      



Update answer:

I can display the navbar using the following code.

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBarHidden = true;
}

@IBAction func buttonTapped(sender: UIButton) {
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

      

Screenshot of implementation: -

enter image description here

+5


source







All Articles