作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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/
我是一名优秀的程序员,十分优秀!