UISearchBar dismiss animation issue
From the code you posted on GitHub I could find a way to avoid the gap, obviously a matter of animation timing.
In your FirstTableViewController.swift you need to register as a delegate of UISearchBar, then trigger yourself the appearing of the navigationBar the earlier possible when the searchBar dismisses (as soon as the text editing ends) with the delegate method searchBarTextDidEndEditing:
Here is your final swift file with 2 additions : the UISearchBarDelegate on line 3, and the function searchBarTextDidEndEditing at the end :
import UIKit
class FirstTableViewController: UITableViewController, UISearchBarDelegate {
var entries: NSArray = ["Foo", "Bar"];
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.entries.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = entries[indexPath.row] as? String
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("test", sender: nil)
}
// Fix searchbar disappear bug
func searchDisplayControllerDidEndSearch(controller: UISearchDisplayController) {
self.tableView.insertSubview(self.searchDisplayController!.searchBar, aboveSubview: self.tableView)
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
}
EDIT - by adjusting the proper layout options in IB, both viewcontrollers work.
First : The 3 checked options for the TableViews are in Drawing: Opaque + Clears Graphics Context + Autoresize Subviews
Second : For the ViewController itself the Extended Edges checked options are: Under Bottom Bars + Under Opaque Bars
And third : the code above about UISearchBar Delegation...
UISearchBar with hidden UINavigationBar
Finnaly!!!! I've found the solution IPHONE: ABPeoplePickerNavigationController hidden navigation bar
UISearchBar in navigationbar
To put searchBar into the center of navigationBar:
self.navigationItem.titleView = self.searchBarTop;
To put searchBar to the left/right side of navigationBar:
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
self.navigationItem.rightBarButtonItem = searchBarItem;
Broken UISearchBar animation embedded in NavigationItem
It looks like Apple still needs to iron out the use of the UISearchBar in the new large title style. If the UIViewController
you push to doesn't have its navigationItem.searchController
set, the animation works fine. When navigating between two instances of UIViewController
that both have a searchController set, you get the issue you describe where the height of the navigation bar jumps.
You can solve (work around) the problem by creating the UISearchController
every time viewDidAppear
gets called (instead of creating it in loadView
) and setting navigationItem.searchController
to nil on viewDidDisappear
.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.async {
let stvc = UITableViewController()
stvc.tableView.dataSource = self
let sc = UISearchController(searchResultsController: stvc)
sc.searchResultsUpdater = self
self.navigationItem.searchController = sc
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.navigationItem.searchController = nil
}
The reason for the asynchronous dispatch is that when setting the navigationItem.searchController
inline in the viewDidAppear
method, an exception is raised:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Only one palette with a top boundary edge can be active outside of a transition. Current active palette is <_UINavigationControllerManagedSearchPalette: 0x7fad67117e80; frame = (0 116; 414 0); layer = <CALayer: 0x60400002c8e0>>'
I know this is only a work around, but hopefully this will help you for now, until Apple solves the issue with navigating between two view controllers that both have a UISearchController
set on their navigationItem
.
UISearchbar squished in UINavigationbar
I recently needed to solve the same issue. I ended up creating a UIBarButtonItem with the back button image asset, and setting that as the navigationItem.leftBarButtonItem
. This button press then calls navigationController?.popViewController(animated: true)
to pop the viewController off the stack
Related Topics
Nsstring Encoding Returns Nil on Url Content
How to Intercept Push Notifications for Another App
Uitableviewcell Separator Disappearing in iOS7
Toplayoutguide in Child View Controller
Ios: Uiview Subclass Init or Initwithframe:
How to Find a Specification in Cocoapods
Resignfirstresponder VS. Endediting for Keyboard Dismissal
Scnbox Different Colour or Texture on Each Face
How to Link Googleanalytics 3.01 with Xcode 5 (Missing Required Architecture X86_64)
Where Does the Indexpath of Dequeuereusablecellwithidentifier:Forindexpath: Get Used
Sending Data from One Viewcontroller to Another
Opening a PDF Document When Clicking a Button
Is There a Public API for Card View UI That Can Be Seen Across iOS 10
How to Change "Initwithnibname" in Storyboard
Change Color of Png in Buttons - iOS
iOS App Crashing Every Other Launch, Can't Find Error