滚动时,hidesBarsOnSwipe从不再显示导航栏 [英] hidesBarsOnSwipe never shows navbar again when scrolling up
问题描述
所以我想在向下滚动时隐藏导航栏并在向上滚动时将其拉回来。隐藏它完美地与
So I want to hide the navbar when scrolling down and bring it back when scrolling up. Hiding it works perfectly with
self.navigationController?.hidesBarsOnSwipe = true
但我希望它在向上滚动时再次显示。我做了一个测试项目,其中视图控制器只有一个覆盖整个屏幕的UICollectionView。然后显示导航栏按预期再次显示,直到我将此行添加到viewDidLoad(将单元格添加到集合视图):
But I expect it to be shown again when scrolling up. I made a test project where the view controller just has a single UICollectionView that covers the whole screen. Then showing the navbar is shown again as expected until I add this line to the viewDidLoad (adding cells to the collection view):
self.collectionView.delegate = self
这就是整个视图控制器的样子
And this is what the whole view controller looks like
class ViewController: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.dataSource = self
self.collectionView.delegate = self
self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "Test")
self.navigationController?.hidesBarsOnSwipe = true
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCellWithReuseIdentifier("Test", forIndexPath: indexPath) as UICollectionViewCell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSizeMake(300, 300)
}
}
<那么为什么当我将单元格添加到我的集合视图时显示导航栏是否停止工作?
So why does showing the navbar stop working when I add cells to my collection view?
推荐答案
我遇到了同样的问题,但是用网络视图。
问题是网页视图的顶部约束是顶部布局指南。顶部,在将顶部约束更改为Superview.Top后问题得以解决。
I had the same problem but with a web view. The problem was that the top constraint of the web view was "Top Layout Guide.Top" , after changing the top constraint to "Superview.Top" the problem was solved.
这篇关于滚动时,hidesBarsOnSwipe从不再显示导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!