3

I am presenting a loading screen where I do not want the navigation bar to be shown. So I use

self.navigationController.navigationBar.hidden = true

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

I have tried using this code but the bar does not appear.

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

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

1
  • What controller or controllers are these statements in, and where do you call them? How is you loading screen getting put on screen? Commented Sep 11, 2014 at 1:56

1 Answer 1

5

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 am able to unhide the navigation bar using the following code.

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

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

Screen shot of the implementation:-

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I am not changing VC's, I am hiding the nav bar in viewDidLoad and am waiting for a JSON response. Once I get the data back I want to close the loading screen then show the navigation bar.
See the updated answer, I can unhide it using a button without a problem. I just tested. I think you are doing something wrong. May be you do not implement the Navigation Controller properly on the storyboard. See: stackoverflow.com/questions/25777465/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.