Ios 当我在搜索栏上单击“取消”时,它消失了
我正在使用UISearchBar,当我单击搜索栏上的“取消”按钮时,它将消失。UITableView移动到搜索栏顶部,搜索栏消失在下方。这是我的密码:Ios 当我在搜索栏上单击“取消”时,它消失了,ios,swift,Ios,Swift,我正在使用UISearchBar,当我单击搜索栏上的“取消”按钮时,它将消失。UITableView移动到搜索栏顶部,搜索栏消失在下方。这是我的密码: searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false searchController.searchBar.placeholder = "Search&q
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search"
searchController.searchBar.searchBarStyle = UISearchBar.Style.prominent
searchController.searchBar.isTranslucent = true
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
definesPresentationContext = true
tableView.separatorStyle = .none
let searchBar = searchController.searchBar
searchBar.backgroundColor = UIColor.white
searchBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width , height: 44)
searchBar.searchBarStyle = UISearchBar.Style.prominent
searchBar.placeholder = " Search book title, author..."
searchBar.sizeToFit()
view.backgroundColor = UIColor.white
searchBar.isTranslucent = true
searchBarView.addSubview(searchBar)
innerView.addSubview(searchBarView)
这可能是因为单击“取消”按钮后,搜索栏会重新计算其帧,并获得零高度。尝试将搜索栏初始化逻辑移动到分离方法,并在UISearchBarDeleteGate的searchBarCancelButtonClicked方法中调用它 另外,我给你的建议是:将部署目标升级到iOS 11,而不是使用搜索栏进行操作,只需使用以下命令:
self.navigationItem.searchController = searchController