兩年前沒(méi)解決的bug終于解決了羡疗。别洪。。挖垛。
剛出UISearchController的時(shí)候,我就遇到需求把searchController放在nav的titleView上痢毒。出現(xiàn)了view出現(xiàn)的時(shí)候會(huì)閃現(xiàn)灰色條的bug送矩,當(dāng)時(shí)趕時(shí)間就讓產(chǎn)品妥協(xié)改到了別的地方
這次又有這需求哪替。。就花心思解決了一下
出現(xiàn)的灰色view是UISearchBarBackground 凭舶,于是remove就好了
為什么是remove,而不是設(shè)置hidden呢帅霜,因?yàn)槲野l(fā)現(xiàn),那個(gè)view消失后是真的消失了身冀。并且設(shè)置hidden是沒(méi)有用的靠汁。
for views in searchController.searchBar.subviews {
printLog(views)
for view in views.subviews {
printLog(view)
if view.isMember(of: NSClassFromString("UISearchBarBackground")!) {
view.removeFromSuperview()
}
}
}
navigationItem.titleView = searchController.searchBar