Swift - Hide navigation bar shows in animation - swift

I am attempting to hide the navigation bar in the app. I did this with the following:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
With this, I am hiding the bar at the top but when the transition is happening I can still see the bar for a split second then it disappears. Image below shows what I mean:
Screenshot showing top nav bar when transitioning from view to another

In your method parameters change ‘animated: animated’ to ‘animated: false’

Related

Prefer large titles for single View Controller

How can I set a large title for a single View Controller embedded in a Navigation Controller?
Normally I am only able to set large titles for a whole Navigation Controller including all View Controllers but i only want one to display a large title.
self.navigationController?.navigationBar.prefersLargeTitles = true
While both of the other answers do the trick, a cleaner way to achieve this is by doing the following in the UIViewController you want:
navigationItem.largeTitleDisplayMode = .always
or for the reverse effect:
navigationItem.largeTitleDisplayMode = .never
This takes away the need to keep track of a state, which in my opinion is a vast improvement
See largeTitleDisplayMode - Apple Developer Documentation for more information on the subject
Only downside is that it's iOS 11.0+
You can set prefersLargeTitles = true in viewWillAppear when ViewController's going to appear and prefersLargeTitles = false in viewWillDisappear when ViewController's going to disappear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.prefersLargeTitles = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.navigationBar.prefersLargeTitles = false
}
You can implement the logic for this viewController only. You can try something like this:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.prefersLargeTitles = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.prefersLargeTitles = false
}

Hiding Bottom Bar When Pushed - Animation freezing on Iphone X

I've encountered an issue that I cannot figure out for the life of me. The issue is only happening on the iPhone X. I've added a little video since its difficult to explain exactly whats happening.
I've also added a screenshot of my storyboard so you can see the flow.
Pretty much were experiencing a freeze when the tab bar is being hidden. It only happens when we visit the category VC (which is presented modally using a segue, it is also embedded in a navigation controller.)
** I'm still new to iOS development so if I'm doing anything terribly wrong feel free to share :)
Video:
https://youtu.be/HC14zFxh-HM
Code that sends to reader:
#IBAction func sendToReader(_ sender: Any) {
let myVC = storyboard?.instantiateViewController(withIdentifier: "ReaderRootVC") as! ReaderRootVC
myVC.book = self.book
myVC.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(myVC, animated: true)
}
Code that closes Category VC:
#IBAction func navigationCancelBtnPressed(_ sender: Any) {
self.navigationController?.dismiss(animated: false, completion: nil)
}
Storyboard:
In your ReaderRootVC,
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Hide the Tab Bar
self.tabBarController?.tabBar.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the Tab Bar
self.tabBarController?.tabBar.isHidden = false
}

Hiding Navigation Bar in Tab Bar Controller

I have my app setup like this:
NavigationController
|-StartViewController
|-Start2ViewController
|-TabBarController
|-Tab1ViewController
|-Tab2ViewController
I want to hide navigation bar in Tab2ViewController but not in Tab1ViewController. So below is my code for Tab2ViewController:
import UIKit
class Tab2ViewController: ICPVC {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("View Wwill Appear Reached")
self.tabBarController!.navigationController!.setNavigationBarHidden(true, animated: false)
}
}
This does not work and navigation bar appears in both Tab1ViewController and Tab2ViewController, however, if I only switch the tabs' position in Interface builder so that Tab2ViewController is the first Viewcontroller in tabs, then it works and navigation bar is hidden in Tab2ViewController and visible in Tab1ViewController
Can't figure out why?

Black view under navigation bar

In my app i have two view controllers embedded in navigation controller (lets say viewControllerA and viewControllerB). In the rootviewcontroller I don't want to show navigation bar, so in viewWillAppear and viewWillDisappear i have added thes lines:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
Now from the viewcontrollerB when back button is typed under navigation bar (when it starts to disapear) black view appears. How to remove that black view?
P.S. I have set navigation bar isTranslucent to false but it does not solve the problem. In my project i'm not using storyboards.
Below answer based on the question owners test project.
From your test project you disabled the navigationController transition(view to view) animation when you hide and unhide navigation bar that causes the black view to appears.
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: true) // set to true
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: true) //set to true
}

Navigation Controllers in Swift

I have embedded my story board view controllers with the navigation controller. However, I want one view specific controller to not have the navigation bar. How can I do this?
Hide the navigation bar in viewWillAppear.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
}
Also, make sure you have it appear again when you leave that particular view controller. I usually do this in viewWillDisappear.
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBarHidden = false
}