当我们push时 searchbar 会闪烁出现(就延迟了出现)
解决方法:
override func viewDidLoad() {
navigationController?.navigationBarHidden = true//去除UISeachbar 的白边闪烁bug(在super前调用)
super.viewDidLoad()
}
override func viewWillAppear(animated: Bool) {
navigationController?.navigationBarHidden = false
super.viewWillAppear(animated)
searchBar.becomeFirstResponder()
}
灰色背景去除
解决方法:
fileprivate lazy var searchBar: UISearchBar = {
let searchBar = UISearchBar()
searchBar.placeholder = "搜索感兴趣的人和问题"
// 去除灰色背景
for view in searchBar.subviews {
if view.subviews.count > 0 {
view.subviews.first?.removeFromSuperview()
break
}
}
return searchBar
}()
最后调用:navigationItem.titleView = searchBar