UISearchController overlaps with the status bar and does not populate iPhone X

I ran into a lot of problems with iOS 11 and displayed UISearchControllerit by presenting it in the navigation bar (as described here , for example, from Apple tutorials)

@IBAction func searchAction(sender: UIBarButtonItem) {
    // Create the search controller and specify that it should present its results in this same view        
    searchController = UISearchController(searchResultsController: nil) 

    // Make this class the delegate and present the search
    self.searchController.searchBar.delegate = self
    presentViewController(searchController, animated: true, completion: nil)
}

It hides the application UINavigationBarand displays UISearchControllerwith a search bar.

Problem 1 .. On iOS 11, it causes the search bar to match the status the first time it appears (it doesn't intersect after retrying).

enter image description here UISearchControllersubmitted for the first time. There is no space between the status bar and the search bar.

enter image description here UISearchControllerpresented again, UINavigationBarmore, and the search bar is the lower status bar.

Problem 2 On iPhone X, it does not cover all the space when presented

enter image description here

, . , iOS 11 , . ? UISearchController iPhone X?

+4
1

Apple " Building Apps for iPhone X" Apple searchController UINavigationBar .

:

if #available(iOS 11, *) {
   self.navigationItem.searchController = searchController;
   searchController.isActive = true;
} else {
   self.present(searchController, animated: true, completion: nil)
}

, iOS 11. , , .

, , , , . , definePesentationContext UIViewController, UISearchController:

//set up UISearchController
self.definesPresentationContext = true;

definePresentationContext true, , UIViewControllers, VC.

+1

Source: https://habr.com/ru/post/1687443/


All Articles