iOS 13 strange search controller gap
Setting
extendedLayoutIncludesOpaqueBars = true
in the UIViewController
used to show the search results, fixed the issue for me.
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
.
Navigation bar issue when search is active and push to next view controller
You can fix this issue by making search controller inactive, then navigate to your details view controller after some delay.
Try following code in you didSelect
method which will help you to hide navigation bar when search controller is active.
searchController.isActive = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
self.navigationController?.pushViewController(<YourViewController>, animated: true)
}
You must required delay to navigate otherwise it's give you warning in console regarding navigation controller presentation process.
So, this code first make your search controller inactive and then navigate to your next view controller.
Related Topics
Why Does Classa Adopting Protocolb Not Satisfy the Protocolb Requirement
How to Add Characters into Dateformatter
Swift Sorting Array of Structs by String Double
Interrupted Purchase Not Calling Delegate After Accepting T&C
Update All Value in One Attribute Core Data
Why Function Return Nil Firebase Swift
Error "{ Expected After If Statement"
How to Convert Unix Timestamp into Swift Nsdate Object
How to Execute Multiplications And/Or Divisions in the Right Order
Exc Bad Access After Coding Signing
Contacts Not Recognized When Body Is Changed from Circle to Rectangle
How to Notify a Queue in Swift (Gcd)
How to Conditionally Define a Podspec Property Depending on Static or Dynamic Usage
What Is a Good or Common Way to Structure a Cli Appliction in Swift