I'm creating a UINavigationController
-based app and want to do it in iOS 12 style: with large titles and the SearchBar
displayed inside the NavigationBar
.
Unfortunately, I have this problem that the SearchBar
will briefly disappear as soon as the animation to the next (or previous) View Controller starts. Once the animation is finished, the Search Bar is visible again. One has to look closely to see it, but if you use the swipe gesture to go back you can see the effect very good.
UISearchBar disappeares when animation between View Controller starts
In order to reproduce the issue outside of my full app I created a simple little app with a UINavigationController
as initial ViewController
and a plain ViewController
(with just a "Next" Button) as RootViewController
in there. Large Titles are set to Automatic in the NavigationItem
, and on the NavigationBar
"Prefers Large Titles" is set to True. In viewDidLoad
in the view controller I assign an instance of UISearchController
to the NavigationItem
as simple as this:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController = searchController
}
}
The "Next" button has a "Show" Segue
to its surrounding View Controller, so I will be able to push the same View Controller over and over again for testing.
What I want is the same behavior as in the iOS 12 Files App: There, the SearchBar
remains static within the NavigationBar
even when navigation happens.
I already spent some good time searching for a solution but could not really find something.
Thanks, Peter