3

The title is a mouthful, but here is what is happening. In iOS 11 when you have a navigation bar with large titles then you scroll down a ways and tap the status bar it will scroll to the top. When it scrolls to the top it gets stuck scrolling past the top.

It looks super messed up, here is an example after it scrolled to the top. It scrolled so far it started pulling the refresh control! scrolled too far

Has anyone seen this and been able to fix it? Mail has a large title and doesn't have the problem, though it is likely not a UICollectionView

Here is a gif of it happening: enter image description here

As far as code goes it is as simple as I can make it:

extension ViewController: UICollectionViewDataSource {
    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 100
    }

    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "fakeCell", for: indexPath) as? UICollectionViewCell
        cell?.backgroundColor = [UIColor.black, .blue, .red, .green, .yellow][indexPath.row % 5]
        return cell!
    }

}
utahwithak
  • 6,235
  • 2
  • 40
  • 62
  • I assume the above is vanilla code, but might still be worth showing. – meaning-matters May 21 '18 at 15:08
  • 1
    Try returning `false` from [scrollViewShouldScrollToTop:](https://developer.apple.com/documentation/uikit/uiscrollviewdelegate/1619378-scrollviewshouldscrolltotop?language=objc) and put your own scroll-to-top code in there. – meaning-matters May 21 '18 at 15:17

3 Answers3

0

Please try this solution:

  • in viewDidLoad - set extendedLayoutIncludesOpaqueBars = true
  • in storyboard - pin collectionView top constraint to superview top with constant = 0 (collectionView will be under navigationbar when translucent)

After that if you tap on statusbar, collectionView stops in the right place.

pawel_d
  • 487
  • 5
  • 9
-1

I had the same problem as you!

In my case I managed to solve this problem by making the navigation bar transluent :

enter image description here

Do not ask me why it works... I have no idea

(I've got the idea there https://stackoverflow.com/a/50639773)

Community
  • 1
  • 1
LetsGoBrandon
  • 498
  • 8
  • 23
-1

I had similar problem like this. In my case the table view was added to a view controller and the table view's top was assigned to safe area. I changed the table view to super view's top. It was working as expected. This may help in ur case if the collection view is added to the view controller. Thanks.

Sivaguru
  • 1
  • 1