gpt4 book ai didi

ios - Swift iOS -NavigationBar hidesBarsOnSwipe 在状态栏下设置 CollectionView Frame 时永远不会重新出现

转载 作者:行者123 更新时间:2023-11-28 06:02:51 32 4
gpt4 key购买 nike

我在 NavigationController 中有一个带有编程 CollectionView 的 tabBar。我注意到向上滑动时,CollectionView 单元格会显示在状态栏下方。为了在我为 CollectionView 配置框架时绕过它,我使用了 view.frame.origin.y + 20,其中 20 是状态栏的高度。我这样做的原因是因为我使用了 view.frame.size.height - tabBarController?.tabBar.frame.size.height 来防止单元格显示在 tabBar 下面并且它起作用了。

我还想在滑动时隐藏导航栏,所以在 ViewDidLoad 中我设置了 navigationController?.hidesBarsOnSwipe = true

问题是,当向上滑动导航栏时,滑动时隐藏并且单元格不再显示在状态栏下方但向下滑动时,导航栏永远不会回来。为什么会这样?

代码:

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.white
navigationItem.title = "Home"

navigationController?.hidesBarsOnSwipe = true

configureCollectionView()
}

func configureCollectionView(){

let frame = CGRect(x: view.frame.origin.x,
y: view.frame.origin.y + 20, // here is where I add + 20 for the statusBar's height
width: view.frame.size.width,
height: view.frame.size.height - tabBarController!.tabBar.frame.size.height) // here is where I subtracted the tabBar's height (- 49)

let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)

collectionView = UICollectionView(frame: frame, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.backgroundColor = UIColor.white
collectionView.alwaysBounceVertical = true
collectionView.showsVerticalScrollIndicator = false
collectionView.register(HomeCell.self, forCellWithReuseIdentifier: homeCell)
view.addSubview(collectionView)

}

最佳答案

这是一个简单的修复。我关注了this answer .

override var prefersStatusBarHidden: Bool {
return navigationController?.isNavigationBarHidden ?? false
}

并确保您的应用程序 .plist 文件中有“View controller-based status bar appearance”=“YES”。

关于ios - Swift iOS -NavigationBar hidesBarsOnSwipe 在状态栏下设置 CollectionView Frame 时永远不会重新出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49089468/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com