Поэтому я хочу скрыть навигацию при прокрутке вниз и вернуть ее при прокрутке вверх. Скрытие его отлично работает с
self.navigationController?.hidesBarsOnSwipe = true
Но я ожидаю, что он будет показан снова при прокрутке вверх. Я сделал тестовый проект, в котором у контроллера вида есть только один UICollectionView, который охватывает весь экран. Затем показ навигационной панели отображается снова, как ожидается, до тех пор, пока я не добавлю эту строку в viewDidLoad (добавив ячейки в представление коллекции):
self.collectionView.delegate = self
И вот как выглядит весь контроллер вида
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)
}
}
Итак, почему отображение навигационной панели перестает работать, когда я добавляю ячейки в мой просмотр коллекции?