Cannot hide status bar if the ViewController is embeded in a NavigationController - ios

As the title says, I cannot hide the status bar, with the regular prefersStatusBarHidden method if my UIViewController is within a UINavigationController.
If I present a UIViewController and the prefersStatusBarHidden returns true the status bar will be hidden, but if I embed the same UIViewController like the following:
let vc = VC()
let navc = UINavigationController(rootViewController: vc)
present(navc, animated: true, completion: nil)
The prefersStatusBarHidden will not be called.
Any hint on why this is happening??

Presumably this is because you are testing on an iPhone X or similar no-bezel device. It is impossible to hide the status bar when there's a navigation bar on such a device.

Related

How to push UIViewController overCurrentContext using UINavigationController

I have a UIViewController that contains a UITabBar. I want to push a new UIViewController that covers the current context (so during the animation it shows the new UIViewController covering the UITabBar). How can I do this?
I have tried using the following to push the view but this is not pushed over the UITabBar.
let vc = ViewController2()
vc.modalPresentationStyle = .overFullScreen
navigationController?.pushViewController(vc, animated: true)
I also thought that maybe I could just hide the UITabBar on ViewController2's viewWillAppear and show it on its viewWilDisappear; however, this just makes the UITabBar appear halfway through the dismissal (it looks really bad if you slowly slide to dismiss the view).
In storyboard, go to the UIViewController you are going to push.
Go to attributes inspector and check "Hide Bottom Bar on Push"
This can also be done programmatically:
let vc = viewController1()
vc.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(vc, animated: true)
Hope it helps!
You must use presentViewController, not push.

Navigation bar is not appearing properly (showing as floating instead of fix bar)

With Navigation bar, why it shows a floating card view instead of the fix navigation bar
?
What will be the configuration to show as a fixed navigation bar?
On iOS 13 or higher, you have to set the UIViewController's modalPresentationStyle to .fullScreen before presenting it.
For example:
let viewController = UIViewController()
viewController.modalPresentationStyle = .fullScreen
present(viewController, animated: true, completion: nil)
You have to do this for every single ViewController you present.

Navigation bar not appearing

Can someone help me with this? :(
The navigation bar is not appearing. This is presented by a rootViewController.
You have not posted any code still guessing.
Just taking UINavigationController in storyboad doesn't means that it will appear by default.
You are just presenting view controller. You need to embed in navigation controller or give storyboard identifier to navigation controller and present that.
Example :
let yourviewController = self.storyboard?.instantiateViewController(withIdentifier: "yourVCIdentifer")
let nav = UINavigationController(rootViewController: yourviewController)
self.present(nav, animated: true, completion: nil)

How do i make a familiar looking status bar on a view controller when i present a particular view controller modally?

When a UIViewController is pushed over a UINavigationController it has a consistent looking native status bar. But when a UIViewController is pushed 'modally' it does not contain a navigation bar. After adding a navigation bar manually the status bar of that UIViewController still remains white. How do i make it consistent to the previous UIViewController's status bar (i.e. grey in colour)
Here's an image to demonstrate the issue visually.
step-1
on your second VC , you need to embed with Navigation Controller, for e.g
step-2
on your second VC, add bar button for dismiss the present VC,
#IBAction func btnback(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}

UIViewController under UINavigationBar?

I have a UINavigationController and a UIViewController as its root view controller.
let rootVC = Page1ViewController() // extends UIViewController
let nav = UINavigationController(rootViewController: rootVC)
presentViewController(nav, animated: true) { () -> Void in
}
The problem is that the content of the rootVC appears under the navigation bar. I tried:
nav.navigationBar.translucent = false
this worked but I want the navigation bar to be transparent and I want the content of the rootVC not appear behind the navigation bar.
I also tried:
nav.edgesForExtendedLayout = UIRectEdge.None
but this does not change anything.
How can I get a transparent navigation bar where the content scrolls under it when scrolling but when loading the content should not appear under the navigation bar?
Remove this line:
nav.edgesForExtendedLayout = UIRectEdge.None
And add this line in your viewDidLoad from Page1ViewController
self.edgesForExtendedLayout = UIRectEdge.None
Hope it helps. Let me know if it doesn´t work and I will help you.
To address your issue of a blackbox now appearing underneath your UINavigationBar you need to set the presentation context properly. Try setting definesPresentationContext on your UINavigationController to NO. This will then use the UIWindow or parent of your UINavigationController as the presentation context.

Resources