gpt4 book ai didi

ios - iOS 导航栏中的搜索栏在触摸时会稍微向下移动

转载 作者:行者123 更新时间:2023-11-30 11:14:04 25 4
gpt4 key购买 nike

我有一个搜索栏,放置在 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

when search bar first loads after tapping search bar

最佳答案

试试这个:

    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

set frames according to your need

关于ios - iOS 导航栏中的搜索栏在触摸时会稍微向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51910737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com