When running the App on iOS 13 beta 6, using Xcode 11 beta 5 I'm encountering the strange gap when presenting search results view controller:
Here's a bit of how this is set up:
let searchResultsController = BLSearchResultsController()
let ret = UISearchController(searchResultsController: searchResultsController)
ret.searchResultsUpdater = self
ret.delegate = self
ret.searchBar.delegate = self;
ret.searchBar.autocapitalizationType = .none
ret.searchBar.placeholder = NSLocalizedString("SearchMsg", comment: "")
ret.searchBar.enablesReturnKeyAutomatically = true
if #available(iOS 13.0, *) {
ret.searchBar.showsScopeBar = false
ret.searchBar.backgroundColor = .white
let searchTextField = ret.searchBar.searchTextField
searchTextField.font = UIFont.tuttiRegularFont(16)
searchTextField.accessibilityIdentifier = "Main Search Field"
if let searchImageView = searchTextField.leftView as? UIImageView {
searchImageView.image = UIImage(named: "home-search-icon")
}
}
The results search controller is a normal UITableViewController
and is just added to the navigationItem.searchController
. There is no fancy presentation code. When building on latest live Xcode and running on the iOS 11/12 device this issue is not present which lead me to believe some underlying iOS 13 change might be causing this glitch.
When debugging the view hierarchy it looks like the result view controller does not reach to the top of the moved search bar.
I've tried fiddling with the modalPresentationModes
trying to exclude the possibility that the changes to the presentation could be the cause, had no luck there.
Has anyone encountered this issue and had luck fixing it?
For me the problem was that UISearchController didn't update it's frame when search bar moved upwards. I fixed it by setting frame of UISearchController to the frame of it's presenting view controller.
In viewWillAppear animation of search bar did not start so you have to wait for a split second. When animation starts, frame of presenting VC is set to the correct value and then you can update frame of your UISearchController. The solution is a hack but it works fine for me.
Setting
in the
UIViewController
used to show the search results, fixed the issue for me.I finally solved this by replacing the UISearchController with a simple(r) UISearchBar.
Maybe not the answer you wanted to hear, but the UISsearchController was already a mess on iOS12, the same code on iOS13 works but give horrible UI artifacts. Like disapearing or overlapping searchbar with the header, white space between the searchbar and the first element of the table, or hiding the first list-item under the scope buttons, ... All different issues between iOS12 and 13, but never looking good.
So overall I spent 6 hours trying to fix the searchcontroller, failed, then spent 30 mins migrating to the Searchbar.
I added the UISearchBar simply using Interface Builder in Xcode10.3. For the refactoring, mostly I had to simply replace searchController.searchBar.xx by searchBar.xx . The main effort was to reimplement the UISeachBarDelegates. Just to only show the scopebuttons and cancel button while the user is searching, and removing them afterwards. The code below gives a good overview of what I did:
FYI I filed a bug report to apple - according to the WWDC presentation that describes the newly re-written SearchController and some other UI updates, it sounds like the architecture of the SearchController has been re-written from the ground up. I can't believe that this gap we are seeing is expected behavior - I've wasted the better part of two days trying to move past this, and I'm not bothering any further - my app store app is a free app that has a number of users and I wasn't able to devote time to tracking changes/behavior in the API during the beta period, I'm somewhat tired of Apple doing this kind of thing on a yearly basis.
You must set yours navigationBar.standardAppearance to an UINavigationBarAppearance object that describes a white background.