Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hidesBarsOnSwipe never shows navbar again when scrolling up

Tags:

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 

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?

like image 541
Andreas Du Rietz Avatar asked Oct 31 '14 13:10

Andreas Du Rietz


1 Answers

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.

like image 114
Oleg Sherman Avatar answered Oct 13 '22 01:10

Oleg Sherman