Hide navigation bar with table view - swift

I'm trying to hide navigation bar when I scroll my table view. It seems that when I scroll inside table view this one can't detect the scrolling event.. when I scroll outside table view navigation bar get hidden...how can I resolve ?

You need to set the navigation controller hideBarsOnSwipe to true
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.hidesBarsOnSwipe = true
}

Related

Adding a prototype cell to a table view in storyboard makes navigation bar title small

I have a View Controller which segues from a previous controller that has large titles. The navigation bar in the navigation controller has the Prefers Large Titles checkbox checked.
I have added a Table View to this new view controller. Until then, the title remains large. However as soon as I add prototype cells to the table view, the navigation bar becomes small.
In code I added this:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBar.prefersLargeTitles = true
}
The problem is, when the view controller comes into view, the title appears small for a second and then immediately shifts to large title.
How can I fix it so that it appear large as I segue and avoid that size shift once the title becomes visible?
it is a feature: when the user scroll, the large Title will disappear and show small title on top.
your problem happend because in the xib file:
your layout is small title and its change to largeTitle when it pushed.
but the view doesn't know that.
to fix this you just need to call: view.layoutIfNeeded() in the viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
title = "Large title"
view.layoutIfNeeded()
}

Search bar behavior inside Navigation Bar is inconsistent in iOS 13

I am trying to include search bar inside the navigation bar through navigation item of the view controller.
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.title = "Sticky Section Headers"
self.edgesForExtendedLayout = .all
self.extendedLayoutIncludesOpaqueBars = true
self.navigationItem.searchController = UISearchController()
setUpNavBarAppearance()
}
This view controller has a collection view and when user taps on a cell in the collection view, i am pushing the a new instance of same view controller(demo purposes) on to the navigation stack..
The behavior for the search controller has been inconsistent between the two view controllers. For the first/root view controller, the search bar shows up by default, but for the second view controller that is pushed on to the navigation controller, the search is hidden by default until user scrolls down.. I would like keep the search appearance behavior consistent across both the screens..
I am aware of the hidesSearchBarWhenScrolling setting to false would keep the search bar visible all the time, but i want to hide the search bar while user is scrolling.
Is there anyway to get the consistent behavior?
Here is the gist file, if you like to try the code:
https://gist.github.com/prasadpamidi/829e636d4697fda025bb0795ee81e355
Appreciate any help.

Tab Bar Controller isHidden, but stays hidden

Im currently designing an app that utilizes a tab bar controller.
On the messages tab (instant messages), I want the tab bar to disappear whenever a user is having/viewing his/her conversation with another person. To do so I used this:self.tabBarController?.tabBar.isHidden = true
It disables the tabBar, but now the issue is that whenever I hit the back button to return to previous views (embedded in a navigation controller), the tab bar is still hidden. On the other views, I've set tabBar.isHidden = false, but that doesn't seem to fix it and now I can't access any of the other tabs.
My question is: How can I hide the tabBar on one view but keep it visible when I return to previous views?
In TabBar firstViewController
override func viewWillAppear(animated: Bool) {
// Enable TabBar
self.tabBarController?.tabBar.hidden = false
}
In SecondViewController (Pushed from firstViewController)
override func viewDidLoad() {
super.viewDidLoad()
// Disable TabBar
self.tabBarController?.tabBar.hidden = true
}

how hide tap bar on another controller before show everything else

I have a simple tap bar example. And for my next view i have a ViewController with tableView and on bottom textInput. when i want hide tap bar i have a code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject? {
if segue.identifier == "showMe" {
(segue.destinationViewController as! MyViewController)
destinationController.hidesBottomBarWhenPushed = true
}
}
and on my next view when i tap a row on tableView i see first rendering tap bar and then tap bar is hidden and on last input Edit goes down :( how hide this tap bar before show next screen ?
This isn't exactly the best solution, but its a workaround:
set destinationController.hidesBottomBarWhenPushed = false
set contraints properly in your view controller (as if there is no tab bar)
use the following code (as shown) in the view controller where you want to hide the tab bar:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tabBarController?.tabBar.frame = CGRectZero
self.tabBarController?.tabBar.userInteractionEnabled = false
}
This will make sure that the tab bar is hidden. Now the Autolayout constraints will make sure your view displays correctly with the tab bar height as zero.

SWRevealViewController hide navigationBar for frontView

I added some code to auto display my MenuViewController (SWRevealViewController) but when I do that, my navigation bar of my front view disappear.
There is the code :
if (previousVC == "EditVC")
{
self.revealViewController().revealToggleAnimated(true)
self.revealViewController().setFrontViewController(self, animated: true)
// navigation bar disappear
}
I don't understand why my navigation bar is hidden. Can somebody help me?
It could be that you are setting the front view controller to a view that's not embedded in a Navigation Controller. My suggestion would be to segue normally and then setup your Sidebar menu again in viewDidLoad for the next view controller like so:
// Implement the menu bar functionality
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
Also, you want to set the next view's navigation controller not its view controller. Since you're not doing a normal segue, you'll lose the navigation controller.
You just need to add one more Navigation Controller between your sw_front Navigation Controller and View Controller and hide the visibility of navigation bar of first navigation controller.