单击搜索栏后将其向下移动(iOS)

时间:2018-08-04 16:05:06

标签: ios iphone swift uisearchbar uisearchcontroller

有一个代码可以创建搜索栏。单击此搜索栏后,然后将其与“取消”按钮一起下移。我附上了屏幕截图和代码。

before click

after click

@IBAction func showSearchBar(_ sender: UIBarButtonItem) {
   self.navigationItem.setRightBarButtonItems([], animated: true)

   self.searchController = UISearchController(searchResultsController: nil)

   self.searchController.searchResultsUpdater = self 
   self.searchController.searchBar.delegate = self 
   self.searchController.delegate = self

   self.searchController.hidesNavigationBarDuringPresentation = false
   self.searchController.obscuresBackgroundDuringPresentation = true
   self.searchController.dimsBackgroundDuringPresentation = false
   self.searchController.searchBar.placeholder = "Искать продукты"

   self.searchController.searchBar.setShowsCancelButton(true, animated: true)
   self.searchController.searchBar.searchBarStyle = .minimal

   self.navigationItem.titleView = searchController.searchBar
   self.definesPresentationContext = true
}

如何解决?

0 个答案:

没有答案