Swift 导航栏标题在第一个VC中激活并取消搜索栏后与新打开的VC重叠
我有一个导航栏,其中包括一个搜索栏,用于过滤当前VC中的表数据,我们称之为First VC 这些步骤在此搜索栏中处于活动状态,并将其取消。然后单击tableView第一个VC的任意一行以打开第二个VC奇怪的行为即将发生,第二个VC的导航标题与第一个VC的导航标题重叠。此外,此问题发生后,右上角的按钮不再可单击。我在从以前的版本12升级到iOS 13时得到了这个 ///首先附上问题截图,您可以看到第一个VC中的标题“音乐”与第二个VC中的标题“播放”重叠 ///第1个VC中的导航条形码Swift 导航栏标题在第一个VC中激活并取消搜索栏后与新打开的VC重叠,swift,uinavigationbar,uisearchbar,ios13,Swift,Uinavigationbar,Uisearchbar,Ios13,我有一个导航栏,其中包括一个搜索栏,用于过滤当前VC中的表数据,我们称之为First VC 这些步骤在此搜索栏中处于活动状态,并将其取消。然后单击tableView第一个VC的任意一行以打开第二个VC奇怪的行为即将发生,第二个VC的导航标题与第一个VC的导航标题重叠。此外,此问题发生后,右上角的按钮不再可单击。我在从以前的版本12升级到iOS 13时得到了这个 ///首先附上问题截图,您可以看到第一个VC中的标题“音乐”与第二个VC中的标题“播放”重叠 ///第1个VC中的导航条形码 over
override func viewDidLoad() {
super.viewDidLoad()
// set tableView's separatorColor
self.tableView.separatorColor = UIColor(rgb: 0x5E5E5E)
// get songs from app's local dir
self.retrieveSongsfromLocalDir()
// add search bar
resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.hidesNavigationBarDuringPresentation = false
controller.obscuresBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
// set search Bar covered color, same with tableView's background color.
controller.searchBar.barTintColor = UIColor(rgb: 0x292f33)
return controller
})() // closure, learn it later!!
navigationItem.searchController = resultSearchController
// reload the tableView
self.tableView.reloadData()
}
///我将导航栏的自定义代码放在AppDelegate.swift中供全局使用
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Custom Navigation Bar's appearance.
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().barTintColor = UIColor(rgb: 0x55acee)
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().clipsToBounds = false
// UINavigationBar.appearance().backgroundColor
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.boldSystemFont(ofSize: 23)]
return true
}
///更新,它与线程重复
https://stackoverflow.com/questions/58134631/ios-13-uibarbuttonitem-not-clickable-and-overlapping-uinavigationbars-when-using
。苹果在iOS 13上的bug似乎是存在的,暂时的解决办法是设置hidesNavigationBarDuringPresentation=true
我也遇到了同样的问题。在模拟器上工作正常,但设备存在问题。