title: Keep active cell in collectionview in one place
body: <p>I'm working on a tvOS application where I want the active cell of a collectionView always in the same position. In other words, I don't want the active cell to go through my collectionView but I want the collectionView to go through my active cell. </p>
  
  <p>Example in the following image. The active label is always in the center of the screen while you can scroll the collectionView to get a different active label over there.</p>
  
  <p>Basically a pickerview with a custom UI. But the pickerview of iOS is unfortunately not provided on tvOS...</p>
  
  <p><a href="https://i.stack.imgur.com/jPFUY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jPFUY.png" alt="Active Cell"></a></p>
  
  <p>I've already looked into <code>UICollectionViewScrollPosition.verticallyCentered</code>. That partially gets me there but it isn't enough. If I scroll really fast, the active item jumps further down the list and when I pause it scrolls up all the way to the center. I really want the active item to be in center of the screen at all times.</p>
  
  <p>Any ideas on how to do this?</p>
  
  <hr>
  
  <p><strong>Update based on @HMHero answer</strong> </p>
  
  <p>Okay, I tried to do what you told me, but can't get the scrolling to work properly. This is perhaps due to my calculation of the offset, or because (like you said) <code>setContentOffset(, animated: )</code> doesn't work.</p>
  
  <p>Right now I did the following and not sure where to go from here;</p>
  
  <p><strong>Disable scrolling and center last and first label</strong></p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      //Disable scrolling
      self.collectionView.isScrollEnabled = false
      //Place the first and last label in the middle of the screen
      self.countryCollectionView.contentInset.top = collectionView.frame.height * 0.5 - 45
      self.countryCollectionView.contentInset.bottom = collectionView.frame.height * 0.5 - 45
  }
  </code></pre>
  
  <p><strong>Getting the position of a label to retrieve the distance from the center of the screen (offset)</strong></p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, didUpdateFocusIn context: UICollectionViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
  if let indexPath = context.nextFocusedIndexPath,
          let cell = countryCollectionView.cellForItem(at: indexPath) {
              //Get the center of the next focused cell, and convert that to position in the visible part of the (tv) screen itself
              let cellCenter = countryCollectionView.convert(cell.center, to: countryCollectionView.superview)
              //Get the center of the collectionView
              let centerView = countryCollectionView.frame.midY
              //Calculate how far the next focused cell y position is from the centerview. (Offset)
              let offset = cellCenter.y - centerView
      }
  }
  </code></pre>
  
  <p>The offset returns incrementals of 100 when printing. The labels' height is 90, and there is a spacing of 10. So I thought that would be correct although it runs through all the way up to 2400 (last label). </p>
  
  <p>Any ideas on where to go from here?</p>