Navigation bar Searchbar Space Is not Hiding in Swift 4.2 - ios

HI i have implemented Searchbar in Navigationbar and
Hiding Navigationbar Progamatically but the space is not removing
PLease help how can i remove the space of searchbar hiding space
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.obscuresBackgroundDuringPresentation = false
search.hidesNavigationBarDuringPresentation = false;
search.searchBar.placeholder = "search..."
self.definesPresentationContext = true
self.navigationItem.searchController = search
for Hiding the SearchBar
search.searchBar.isHidden = false

Hiding it won't be enough because it is still the navigationItem searchController, so you need to set it to nil
self.navigationItem.searchController = nil
and later restore it if you want, simple as that.

Related

Search Bar disappears in scrolling, how to prevent this action

My search bar seems to disappear on scrolling, even if i were use
navigationController?.hidesBarsOnSwipe = false
Also using below
navigationItem.searchController = searchController
has no effect
Seems to have no effect, my code for search controller addition is
searchControlInstance = UISearchController(searchResultsController: nil)
searchControlInstance.searchResultsUpdater = self
searchControlInstance.obscuresBackgroundDuringPresentation = false
self.definesPresentationContext = true
searchControlInstance.searchBar.returnKeyType = .done
navigationItem.hidesSearchBarWhenScrolling = false
I do have
navigationController?.navigationBar.prefersLargeTitles = true
but turning it to false seems to have no effect the search bar just disappears like in picture, where am i making the mistake, can any one suggest, i do not use storyboard
You have to set it in this way:
navigationItem.searchController = searchControlInstance
navigationItem.hidesSearchBarWhenScrolling = false

Smooth disappearance of iOS 11 search bar

I am running into a small problem, I implemented the new iOS 11's style search bar in my app, and I noticed that it disappeared with a slightly different animation from the one in Messages for example. It's faster and less smooth.
Anyone has ever stumble upon this "problem" ?
Here is the code I use :
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.delegate = self
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.barTintColor = .white
searchController.searchBar.layer.borderColor = UIColor.white.cgColor
searchController.searchBar.layer.borderWidth = 1
}
definesPresentationContext = true
searchController.searchBar.placeholder = "all_search".localized
EDIT:
I don't know if it will help you, but I am scrolling at a normal pace .
Thanks
Adding
self.extendedLayoutIncludesOpaqueBars = true
to my viewDidLoad solved the issue, your navigation bar must not be translucent and note that extendedLayoutIncludesOpaqueBars = true is being attributed to my main view which holds the tableview.
This happens when your table view doesn't go all the way to the top of the view. Make sure your table view is "behind" the navigation bar and uses extended edges and extend under opaque edges if your navigation bar is opaque.
Try this, it fixes it for me. I used a different UIViewController as the searchResultsUpdater and just set extendedLayoutIncludesOpaqueBars as true.
searchResultsUpdater.extendedLayoutIncludesOpaqueBars = true
searchController.searchResultsUpdater = searchResultsUpdater
UIView.animate(withDuration: 1, animations: {
//your codes to implement
}, completion: nil)
change withDuration: in seconds

container view under navigation bar didnt shift up when search bar selected

I customly add UISearchBar controller in the navigationItem. And it works fine on iphone but giving issue on ipad.
I am using a container view under the navigation bar on which i am calling different view controllers. But as soon as i select the search bar the search bar goes up to hide the status bar but the container view under the navigation didn't shift up.
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.placeholder = "Search"
if let textfield = self.searchController.searchBar.value(forKey: "searchField") as? UITextField {
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
self.searchController.searchBar.tintColor = UIColor.cityworksBlue()
if #available(iOS 11.0, *) {
self.searchController.searchBar.showsScopeBar = false;
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = true
navigationItem.searchController = self.searchController
navigationItem.hidesSearchBarWhenScrolling = false
}
What i want to do is if search bar shifts upwards then container view should also shift upward. It works in iphones but giving problem in ipad.
I found my solution by selection "Under Top Bars" option.

How to stop search bar from hiding on scroll

I have a UINavigationController that has a UISearchController assigned to the navigationItem's searchController. Inside the view I have a UICollectionView. The search bar displays in the navigation bar, but when I scroll, the navigation bar automatically hides. Can I stop this from happening?
let searchController = UISearchController(searchResultsController: recentSearchesViewController)
searchController.searchResultsUpdater = recentSearchesViewController
searchController.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
navigationItem.searchController = searchController
You have to set :
navigationItem.hidesSearchBarWhenScrolling = false

UISearchController woes

I'm having an issue with UISearchController. There have been some reports of erratic behavior in iOS 11, but none of the suggestions have fixed my problem.
The navigation bar is hidden in my app so I just want to place the search bar between two buttons on the main screen. I put UIView in the storyboard to serve as the superview for the search bar. When activated the results controller is a straight UITableViewController.
Everything is in-place when the app launches. When I access the search bar it just to the top of the screen, leaving it's parent view behind. Everything functions ok, but when I hide the table view, the search bar actual goes a bit lower than it was when it started. Here's the setup code:
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearchTable") as! LocationSearchTable
searchController = UISearchController(searchResultsController: locationSearchTable)
searchController.searchResultsUpdater = locationSearchTable
searchController.delegate = self
locationSearchTable.mapView = mapView
locationSearchTable.handleMapSearchDelegate = self
locationTableController = locationSearchTable
let searchBar = searchController!.searchBar
//searchBar.searchBarStyle = UISearchBarStyle.prominent
searchBar.sizeToFit()
searchBar.placeholder = "Search..."
searchViewHolder.addSubview(searchBar)
searchBar.frame = searchViewHolder.bounds
searchBar.autoresizingMask = [.flexibleWidth, .flexibleHeight]
searchController.dimsBackgroundDuringPresentation = true
definesPresentationContext = false
I have tried many, many approaches to fixing this. I'm wondering if I misunderstood an earlier suggestion. Any advice is welcome.
I'd the same issue. If your navbar is not translucent try to put this in viewDidLoad:
extendedLayoutIncludesOpaqueBars = true

Resources