Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS NavigationBar中的搜索栏在触摸时轻微向下移动_Ios_Swift_Uisearchbar_Uisearchcontroller_Googleplacesautocomplete - Fatal编程技术网

iOS NavigationBar中的搜索栏在触摸时轻微向下移动

iOS NavigationBar中的搜索栏在触摸时轻微向下移动,ios,swift,uisearchbar,uisearchcontroller,googleplacesautocomplete,Ios,Swift,Uisearchbar,Uisearchcontroller,Googleplacesautocomplete,我有一个搜索栏,我把它放在Google Place AutoComplete的导航栏里面。当它出现时显示良好,但当您点击它的内部时,它会稍微向下移动,并保持在那里,即使您点击“取消”,直到您将titleView设置为“零”并再次返回,然后它会重置。以下是在我的viewDidLoad方法中调用的相关代码: resultsViewController = GMSAutocompleteResultsViewController() resultsViewController?.delegat

我有一个搜索栏,我把它放在Google Place AutoComplete的导航栏里面。当它出现时显示良好,但当您点击它的内部时,它会稍微向下移动,并保持在那里,即使您点击“取消”,直到您将titleView设置为“零”并再次返回,然后它会重置。以下是在我的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

试试这个: 根据需要设置框架


尝试在不同的元素上添加不同的背景色,以确定某个元素是否比您预期的要高。
    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