0

I have a UICollectionView that scrolls vertically. The collection view is a form. It has multiple sections, each section has a few items in it. The top section has a header which is pinned to the top of the view so it remains in place as the content scrolls.

The problem is, as I scroll the content up, the items show against the status bar. How do I get the items to be hidden as I scroll? Can I set a color to the status bar, or set an inset on the view?

Notice in the behavior in the screenshot below:

enter image description here

tentmaking
  • 2,076
  • 4
  • 30
  • 53

1 Answers1

1

The usual thing is to pin the top of the collection view to the top Safe Area layout guide.

(But the whole thing looks a lot better, in my opinion, if you are also inside a navigation controller.)

EDIT It appears from your subsequent query (in a comment) that you are using a UICollectionViewController (you did not mention that in your question). So the answer boils down to: never use a "bare naked" UICollectionViewController. Always use it as a child view controller, in one of these ways:

  • As the child of a UINavigationController, because the collection view's top will then be concealed by the navigation bar

  • Or, through a Container View and an embed segue, because then you can pin the container view's top to the safe area top.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • How do I do that in a Storyboard where I'm using a UICollectionViewController and I cannot adjust the constraints? – tentmaking Sep 22 '18 at 16:38
  • You should always use a UICollectionViewController either as the child of a UINavigationController, as I said in my answer, or through an Embed segue where you configure the container view to position the collection view. – matt Sep 22 '18 at 17:07