推送搜索结果后,顶部布局指南移动到导航栏下方
Top layout guide moves underneath navigation bar after pushing search results
这个已经好几天了。我认为说明我的问题的最简单方法是使用这个 10 秒的 gif。
描述
如您所见,当您在推送到搜索结果后返回时,返回时分段顶部栏消失了,但是当我切换到 [=54= 中带有 "Tise" 的选项卡时] 并返回,它会重置并正常工作。
如以下屏幕截图所示,我的问题是顶部布局指南在导航栏下方偏移,这使得分段栏隐藏在其下方。
代码
我的搜索控制器是一个非常正常的实现。
/* Search controller */
let exploreSearchController = StandaloneExploreSearchResultController.initFromStoryboard(type: .top)
searchController = UISearchController(searchResultsController: exploreSearchController)
searchController?.searchResultsUpdater = exploreSearchController
searchController?.delegate = self
searchController?.searchBar.searchBarStyle = .minimal
searchController?.searchBar.isTranslucent = false
searchController?.searchBar.backgroundColor = .clear
searchController?.hidesNavigationBarDuringPresentation = false
searchController?.dimsBackgroundDuringPresentation = false
searchController?.searchBar.tintColor = #colorLiteral()
navigationItem.titleView = searchController?.searchBar
definesPresentationContext = true
然后我用
将结果控制器推送到StandaloneExploreSearchResults
presentingViewController?.navigationController?.pushViewController(viewController, animated: true)
对于每个新的视图控制器,我都会更新导航栏样式,我怀疑这可能会触发它。如果我禁用此功能,我会得到不同的偏移错误,如下面的 gif 所示。
func updateNavigationBarStyle(viewController: UIViewController) {
let style = (viewController as? NavigationControllerStyling)?.preferredStyle() ?? .default
print(#file.components(separatedBy: "/").last!,":",#line,"-",#function, viewController.classForCoder)
//Showhide
UIApplication.shared.setStatusBar(hidden: style.statusBar.hidden, style: style.statusBar.style)
setNavigationBarHidden(style.hidden.hidden, animated: style.hidden.animated)
navigationBar.setCustomShadow(hidden: style.shadowHidden)
//Colors
navigationBar.tintColor = style.tintColor
navigationBar.barTintColor = style.barTintColor
navigationBar.backgroundColor = style.backgroundColor
navigationBar.setBackgroundImage(style.backgroundImage, for: .default)
navigationBar.titleTextAttributes = style.titleTextAttributes
navigationBar.isTranslucent = style.translucent
navigationBar.hairlineImageView?.isHidden = true //Always hide the native shadow
}
问题
有没有办法或者强制重新加载切换选项卡触发的自动布局(我已经尝试了我能找到的所有方法但没有成功)。 或 以某种方式修复错误?
在 viewDidLoad
-
中尝试此代码
self.edgesForExtendedLayout = []
好吧,那就解决了。我想设置颜色 and/or 图像以某种方式摆弄了不透明 属性.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
extendedLayoutIncludesOpaqueBars = true
}
这个已经好几天了。我认为说明我的问题的最简单方法是使用这个 10 秒的 gif。
描述
如您所见,当您在推送到搜索结果后返回时,返回时分段顶部栏消失了,但是当我切换到 [=54= 中带有 "Tise" 的选项卡时] 并返回,它会重置并正常工作。
如以下屏幕截图所示,我的问题是顶部布局指南在导航栏下方偏移,这使得分段栏隐藏在其下方。
代码
我的搜索控制器是一个非常正常的实现。
/* Search controller */
let exploreSearchController = StandaloneExploreSearchResultController.initFromStoryboard(type: .top)
searchController = UISearchController(searchResultsController: exploreSearchController)
searchController?.searchResultsUpdater = exploreSearchController
searchController?.delegate = self
searchController?.searchBar.searchBarStyle = .minimal
searchController?.searchBar.isTranslucent = false
searchController?.searchBar.backgroundColor = .clear
searchController?.hidesNavigationBarDuringPresentation = false
searchController?.dimsBackgroundDuringPresentation = false
searchController?.searchBar.tintColor = #colorLiteral()
navigationItem.titleView = searchController?.searchBar
definesPresentationContext = true
然后我用
将结果控制器推送到StandaloneExploreSearchResults
presentingViewController?.navigationController?.pushViewController(viewController, animated: true)
对于每个新的视图控制器,我都会更新导航栏样式,我怀疑这可能会触发它。如果我禁用此功能,我会得到不同的偏移错误,如下面的 gif 所示。
func updateNavigationBarStyle(viewController: UIViewController) {
let style = (viewController as? NavigationControllerStyling)?.preferredStyle() ?? .default
print(#file.components(separatedBy: "/").last!,":",#line,"-",#function, viewController.classForCoder)
//Showhide
UIApplication.shared.setStatusBar(hidden: style.statusBar.hidden, style: style.statusBar.style)
setNavigationBarHidden(style.hidden.hidden, animated: style.hidden.animated)
navigationBar.setCustomShadow(hidden: style.shadowHidden)
//Colors
navigationBar.tintColor = style.tintColor
navigationBar.barTintColor = style.barTintColor
navigationBar.backgroundColor = style.backgroundColor
navigationBar.setBackgroundImage(style.backgroundImage, for: .default)
navigationBar.titleTextAttributes = style.titleTextAttributes
navigationBar.isTranslucent = style.translucent
navigationBar.hairlineImageView?.isHidden = true //Always hide the native shadow
}
问题
有没有办法或者强制重新加载切换选项卡触发的自动布局(我已经尝试了我能找到的所有方法但没有成功)。 或 以某种方式修复错误?
在 viewDidLoad
-
self.edgesForExtendedLayout = []
好吧,那就解决了。我想设置颜色 and/or 图像以某种方式摆弄了不透明 属性.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
extendedLayoutIncludesOpaqueBars = true
}