我在Google Place AutoComplete的导航栏中放置了一个搜索栏。当它出现时,它会很好地显示,但是当您在其中轻按时,它会稍微向下移动并停留在该位置,即使您单击“取消”也是如此,直到将titleView设置为nil然后再次返回,然后重置。这是在我的viewDidLoad方法中调用的相关代码:
resultsViewController = GMSAutocompleteResultsViewController()
resultsViewController?.delegate = self
searchController = UISearchController(searchResultsController: resultsViewController)
searchController?.searchResultsUpdater = resultsViewController
searchController?.searchBar.sizeToFit()
searchController?.hidesNavigationBarDuringPresentation = false
definesPresentationContext = true
navigationController?.navigationBar.isTranslucent = true
searchController?.hidesNavigationBarDuringPresentation = false
navigationItem.titleView = nil
然后在需要时将其设置如下:
navigationItem.titleView = searchController?.searchBar
答案 0 :(得分:0)
searchController.searchBar.frame = CGRect(center: CGPoint(x: 15,y: 10), size: CGSize(width: 30, height: 30))
let vu = UIView(frame: CGRect(center: .zero, size: CGSize(width: self.view.frame.width - 10, height: 40)))
vu.addSubview(searchController.searchBar)
vu.backgroundColor = UIColor.clear
navigationItem.titleView = vu
根据您的需要设置框架