title: Swift: Hide and Show UISegmentedControl in UICollectionView when scrolling
body: <p>I need to hide my <code>UISegmentedControl</code> in my <code>UICollectionView</code> when the collection is scrolling. Below my snippet code : </p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
  .....
  .....
  if (collectionViewMovie.contentOffset.y &gt; 100) {
          self.segmentedControl.isHidden = true
      } else if (collectionViewMovie.contentOffset.y &lt; 100) {
          self.segmentedControl.isHidden = false
      }
  }
  </code></pre>
  
  <p>Its work to hide when the collection is scrolling. But sometimes the segmented is not show when I scroll slowly to the top. Its not smooth too when hidden the UISegmentedControl. I <a href="https://stackoverflow.com/questions/11976176/creating-a-hidden-uisegmentedcontrol-in-a-uitableview">read</a> this but its on Objective C. I read <a href="https://stackoverflow.com/questions/31928394/ios-swift-hide-show-uitabbarcontroller-when-scrolling-down-up">this</a> to but its on UIScrollView. Any suggest and answer will help for me. Thanks in Advance</p>
  
  <p>*Edit </p>
  
  <pre><code> func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
      if scrollView.panGestureRecognizer.translation(in: self.view).y &lt; 0 {
          self.segmentedControl.isHidden = true
      } else {
      self.segmentedControl.isHidden = false
      }
  }
  </code></pre>
  
  <p>Now its always show or hide when scrolling even smooth scroll, but there is stil no animation. Thanks again in advance</p>