gpt4 book ai didi

ios - 搜索栏从 iPhone 上的“搜索”按钮展开

转载 作者:行者123 更新时间:2023-11-28 05:33:12 24 4
gpt4 key购买 nike

当我单击搜索按钮时,如何使我的搜索栏在导航栏中展开,就像 Twitter 应用程序中的那样?现在我的搜索栏刚好落在导航栏的顶部。这是我在单击导航栏中的搜索按钮时调用的函数:

func searchbuttonclicked(sender: UIBarButtonItem) {
var searchresults = storyboard?.instantiateViewControllerWithIdentifier("searchresults") as searchResultsController

var searchcontroller = UISearchController(searchResultsController: searchresults)
searchcontroller.hidesNavigationBarDuringPresentation = false
searchcontroller.searchResultsUpdater = searchresults
searchcontroller.modalTransitionStyle = .CrossDissolve

presentViewController(searchcontroller, animated: true, completion: nil)
}

最佳答案

来自 this answer ,你可以使用类似的东西:

// declare as property
var searchBar: UISearchBar!

// in viewDidLoad
searchBar = UISearchBar(frame: CGRectMake(0.0, -80.0, 320.0, 44.0))
navigationController?.navigationBar.addSubview(searchBar)

// in action to show
searchBar.frame = CGRectMake(0.0, 0, 320, 44)

// in viewWillDisappear
searchBar.removeFromSuperview()

但是,UISearchController 上的 searchBar 属性是只读的,因此您需要子类化 UISearchController 以使其使用搜索导航 Controller 中的栏,而不是它默认显示的栏。

关于ios - 搜索栏从 iPhone 上的“搜索”按钮展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26727061/

24 4 0