title: UICollectionview how to avoide top bar by scrolling
body: <p>When I start my App everything is fine.</p>
  <p><a href="https://i.stack.imgur.com/ICikt.png" rel="nofollow noreferrer">As it should stay.</a></p>
  <p>But as soon I start to scroll down a strange Bar at the Top appears.
  <a href="https://i.stack.imgur.com/fSOBC.png" rel="nofollow noreferrer">Strange Bar by Scrolling down</a></p>
  <p>I looked for some frame issue but I can't find one. I have no Idea what causes this behavior. I coded my UICollectionview programmatically.</p>
  <p>Here is my Code:</p>
  <pre><code>    import UIKit
  
  // MARK: Erzeugung &amp; Füllen des Daten STRUCT
  struct Profile {
      let name: String
      let location: String
      let imageName: String
      let profession: String
  }
  
  var profiles: [Profile] = []
  
  private func populateProfiles() {
      profiles = [
          Profile(name: &quot;Thor&quot;, location: &quot;Boston&quot;, imageName: &quot;astronomy&quot;, profession: &quot;astronomy&quot;),
          ...
          Profile(name: &quot;Elon Musk&quot;, location: &quot;San Francisco&quot;, imageName: &quot;graduate&quot;, profession: &quot;graduate&quot;)
      ]
  }
  
  class ViewController: UIViewController {
  
      private let collectionView: UICollectionView = {
          let viewLayout = UICollectionViewFlowLayout()
          let collectionView = UICollectionView(frame: .zero, collectionViewLayout: viewLayout)
          // collectionView.backgroundColor = .white
          return collectionView
      }()
      
  // MARK: Hintergrundbild erzeugen
      let imageView : UIImageView = {
          let iv = UIImageView()
          iv.image = UIImage(named:&quot;Backround-wood&quot;)
          iv.contentMode = .scaleAspectFill
          return iv
      }()
  
      private enum LayoutConstant {
          static let spacing: CGFloat = 50.0 //Größe der Zwischenräume
          static let itemHeight: CGFloat = 500.0 //Zellhöhe
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          setupViews()
          setupLayouts()
          populateProfiles() // finales Befüllen des STRUCT
          collectionView.reloadData()
          
          self.collectionView.backgroundView = imageView //Hintergrundbild einfügen
      }
  
      
  // MARK: Rotation - Resize-Cells &amp; Transition
      override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
          super.viewWillTransition(to: size, with: coordinator)
          coordinator.animate(
              alongsideTransition: { _ in self.collectionView.collectionViewLayout.invalidateLayout() },
              completion: { _ in }
          )
      }
      
      private func setupViews() {
          view.backgroundColor = .white
          view.addSubview(collectionView)
  
          collectionView.dataSource = self
          collectionView.delegate = self
          collectionView.register(ProfileCell.self, forCellWithReuseIdentifier: ProfileCell.identifier)
          collectionView.contentInsetAdjustmentBehavior = .never // Cells starten weiter oben
      }
  
  // MARK: Constraints collectionView
      private func setupLayouts() {
          collectionView.translatesAutoresizingMaskIntoConstraints = false
          NSLayoutConstraint.activate([
              collectionView.topAnchor.constraint(equalTo: view.topAnchor),       //view.safeAreaLayoutGuide.topAnchor),
              collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor), //view.safeAreaLayoutGuide.bottomAnchor),
              collectionView.leftAnchor.constraint(equalTo: view.leftAnchor),
              collectionView.rightAnchor.constraint(equalTo: view.rightAnchor)
          ])
      }
  
      init() {
          super.init(nibName: nil, bundle: nil)
      }
  
      required init?(coder: NSCoder) {
          fatalError(&quot;init(coder:) has not been implemented&quot;)
      }
  }
  
  extension ViewController: UICollectionViewDataSource {
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return profiles.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ProfileCell.identifier, for: indexPath) as! ProfileCell
  
          let profile = profiles[indexPath.row]
          cell.setup(with: profile)
          cell.contentView.backgroundColor = .red
          return cell
      }
  }
  
  extension ViewController: UICollectionViewDelegateFlowLayout {
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
          let width = itemWidth(for: view.frame.width, spacing: LayoutConstant.spacing)
  
          return CGSize(width: width, height: LayoutConstant.itemHeight)
      }
  
      func itemWidth(for width: CGFloat, spacing: CGFloat) -&gt; CGFloat {
          let itemsInRow: CGFloat = 2
  
          let totalSpacing: CGFloat = 2 * spacing + (itemsInRow - 1) * spacing
          let finalWidth = (width - totalSpacing) / itemsInRow
  
          return floor(finalWidth)
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {
          return UIEdgeInsets(top: LayoutConstant.spacing, left: LayoutConstant.spacing, bottom: LayoutConstant.spacing, right: LayoutConstant.spacing)
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {
          return LayoutConstant.spacing
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {
          return LayoutConstant.spacing
      }
  }
  </code></pre>
  <p>Can somebody please help?</p>