iOS 13 strange search controller gap

2020-05-20 07:24发布

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:

enter image description here

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?

11条回答
ゆ 、 Hurt°
2楼-- · 2020-05-20 08:16

Just bringing my solution. In my case:

edgesForExtendedLayout = .all

on the UIViewController that contains the UISearchController worked.

//MARK: - Properties
var presenter: ExplorePresenting?
var searchController: UISearchController?
var searchUpdater: SearchUpdating?


//MARK: - Lifecycle methods
public override func viewDidLoad() {
    super.viewDidLoad()

    headerTitle = "explore".localised
    tableView.allowsSelection = false
    registerCell(cellClass: ExploreTableViewCell.self, with: tableView)

    if let searchController = searchController {

        searchController.searchBar.delegate = self
        searchController.searchResultsUpdater = self
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "explore_search_placeholder".localised

        definesPresentationContext = true
        navigationItem.hidesSearchBarWhenScrolling = false
        navigationItem.searchController = searchController
        edgesForExtendedLayout = .all

    }

    presenter?.viewReady()

}
查看更多
兄弟一词,经得起流年.
3楼-- · 2020-05-20 08:20

extendedLayoutIncludesOpaqueBars = true did help to some extent.

Along with this, I had to update

navigationController?.navigationBar.prefersLargeTitles = false

when we start searching and set it back to true when search bar is dismissed.

查看更多
男人必须洒脱
4楼-- · 2020-05-20 08:21

Finally get through the tough. Just to make the first controller contains the UISearchController to have a translucent navigationBar. Work for me perfectly!

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationController?.navigationBar.isTranslucent = true
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationController?.navigationBar.isTranslucent = false
    }
查看更多
乱世女痞
5楼-- · 2020-05-20 08:22

We had the same issue and the solution was to set Under Opaque Bars (since we use opaque bars) Under Opaque Bars

We already had Top and Bottom checked, adding the third moved the search results controller to the correct location.

查看更多
够拽才男人
6楼-- · 2020-05-20 08:24

Using .asyncAfter(deadline: .now() + 0.1) will cause a glitch in the UI. To get rid of that, get rid of the deadline! Using DispatchQueue.main.async is enough.

extension UISearchController {
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if let presentingVC = self.presentingViewController {
            DispatchQueue.main.async {
                self.view.frame = presentingVC.view.frame
            }
        }
    }
}
查看更多
登录 后发表回答