我在UISearchController中实现了UISearchbar,它放在UIView中。但是搜索栏在iPad中并不合适。在iPhone中,它可以通过根据堆栈溢出答案设置sizeToFit和frame.size.width来正常工作。请帮我配合iPad使用。 我按照此链接中的答案进行了操作 - Display UISearchController's searchbar programmatically
var pickUpresultsViewController: GMSAutocompleteResultsViewController?
var pickUpSearchController: UISearchController?
pickUpresultsViewController = GMSAutocompleteResultsViewController()
pickUpresultsViewController?.delegate = self
pickUpSearchController = UISearchController(searchResultsController: pickUpresultsViewController)
pickUpSearchController?.searchResultsUpdater = pickUpresultsViewController
pickUpSearchController?.searchBar.placeholder = "From:"
pickUpView.addSubview((pickUpSearchController?.searchBar)!)
pickUpSearchController?.searchBar.sizeToFit()
// For some reason, the search bar will extend outside the view to the left after calling sizeToFit. This next line corrects this.
pickUpSearchController?.searchBar.frame.size.width = pickUpView.frame.size.width
definesPresentationContext = true
pickUpSearchController?.hidesNavigationBarDuringPresentation = false