【发布时间】:2018-04-10 23:13:19
【问题描述】:
在导航栏中,我添加了一个搜索栏。它改变了导航栏的高度。我还调整了框架高度以使其看起来更好。以下所有代码都可以正常工作:
let locationSearchTableVC = storyboard!.instantiateViewController(withIdentifier: "LocationSearchTableVC") as! LocationSearchTableVC
resultSearchController = UISearchController(searchResultsController: locationSearchTableVC)
resultSearchController?.searchResultsUpdater = locationSearchTableVC as UISearchResultsUpdating
self.parent?.navigationItem.titleView = self.resultSearchController?.searchBar
let searchBar = resultSearchController!.searchBar
searchBar.delegate = self
searchBar.sizeToFit()
searchBar.placeholder = searchBarPlaceHolder
resultSearchController?.hidesNavigationBarDuringPresentation = false
resultSearchController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
locationSearchTableVC.mapView = mapView
locationSearchTableVC.handleMapSearchDelegate = self
textFieldInsideUISearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideUISearchBar?.textColor = UIColor.gray
let textFieldInsideSearchBarLabel = self.textFieldInsideUISearchBar!.value(forKey: "placeholderLabel") as? UILabel
textFieldInsideSearchBarLabel?.textColor = UIColor.gray
textFieldInsideUISearchBar?.backgroundColor = UIColor(red: 212/255, green: 215/255, blue: 220/255, alpha: 1)
let bounds = self.navigationController!.navigationBar.bounds
let statusBarHeight = UIApplication.shared.statusBarFrame.height
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + statusBarHeight)
-
当用户点击 tableView 单元格时,我会使用 pushViewController 转换到另一个 viewController:
self.navigationController?.pushViewController(viewController2, animated: true)
目标是在推送后保持导航栏的大小,但我无法让它工作。请注意,在第二张图片中,它没有第一张那么高。
我尝试添加一个新的 searchBar(我会将其设置为半透明)、调整框架大小等,但无法让它移动。
事实上,如果我在第二个 viewController 中设置框架大小,则导航栏高度会折叠以占据状态栏的区域。很奇怪。
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: previousNavBarHeight!)
如果我设置self.additionalSafeAreaInsets.top,我可以将navigationBar下方的内容推到它应该在的位置,但navigationBar本身的高度不会增加。
我在其他帖子中看到 iOS11 在设置高度方面发生了变化,但我尝试过的解决方案都没有奏效。
【问题讨论】:
标签: swift uinavigationcontroller uinavigationbar