【发布时间】:2017-07-20 19:12:13
【问题描述】:
您好,我在 UIView 上添加了搜索栏。当我运行我的代码时,我可以看到我的搜索栏,但是当我在搜索栏中点击它时它会隐藏起来,当我再次点击屏幕上的某个地方时它是可见的。我现在没有遇到这个问题。请帮忙。
var searchView:UIView = {
var search = UIView()
search.translatesAutoresizingMaskIntoConstraints = false
search.backgroundColor = UIColor.gray
return search
}()
lazy var searchController : UISearchController = {
var searchController = UISearchController(searchResultsController: nil)
//searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.barTintColor = UIColor.gray
searchController.searchBar.layer.borderWidth = 1
searchController.searchBar.layer.borderColor = UIColor.gray.cgColor
//searchController.dimsBackgroundDuringPresentation = false
searchController.definesPresentationContext = true
searchController.searchBar.sizeToFit()
searchController.searchBar.translatesAutoresizingMaskIntoConstraints = false
return searchController
}()
func setUpView(){
view.addSubview(searchView)
searchView.addSubview(searchController.searchBar)
searchView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
searchView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
searchView.topAnchor.constraint(equalTo: view.topAnchor,constant:64).isActive = true
searchView.heightAnchor.constraint(equalToConstant: 65).isActive = true
searchController.searchBar.leftAnchor.constraint(equalTo: searchView.leftAnchor).isActive = true
searchController.searchBar.rightAnchor.constraint(equalTo: searchView.rightAnchor).isActive = true
searchController.searchBar.topAnchor.constraint(equalTo: searchView.topAnchor,constant:10).isActive = true
searchController.searchBar.widthAnchor.constraint(equalTo: searchView.widthAnchor).isActive = true
}
我也在 ViewDidLoad()-:
中给出了这一行self.extendedLayoutIncludesOpaqueBars = true
【问题讨论】:
-
我不明白这个问题,所以您希望它在您在外面点击时可见还是不希望它可见?您的评论:“我现在没有收到这个问题。”让我更加困惑。
-
@brw59 我的意思是,当我在 UISearchBar 字段内点击时,UISearchBar 会隐藏自己,我看不到它,但是当我再次点击控制器屏幕上的某个地方时,它会再次显示。所以我不想要它隐藏。
标签: ios swift swift3 uisearchcontroller