0

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

PeterW
  • 1
  • 4
  • This may help https://stackoverflow.com/questions/5095477/uisearchbar-in-navigationbar – algrid Dec 15 '18 at 17:43
  • Thanks, but I cannot see anything in there that might help with my Search Bar briefly disappearing when going back and forward in the navigation stack. The problem is not that the Search Bar is not visible at all or something like this. Basically functionality-wise everything is working fine, I just think it should not flicker as it does not do that in iOS 12's Files app. – PeterW Dec 16 '18 at 09:07
  • @vikash-kumar Thanks for showing me how to improve the formatting. I'm new here so I'm always learning... – PeterW Dec 16 '18 at 09:12

0 Answers0