title: How to auto scroll UICollectionview in one direction swift?
body: <p>good noon</p>
  
  <p>I need to scroll uicollection view cell in one direction.</p>
  
  <p><strong>For Example:-</strong> </p>
  
  <p>I have array with 4 data value -> ["apple","pen","book","bottle"].</p>
  
  <p>I need to scroll Uicollectionview cell like this: </p>
  
  <p><strong>apple -> pen -> book -> bottle -> apple -> pen -> book -> bottle -> continue..</strong></p>
  
  <p>i used this code for auto scroll but in my case collection view scroll like:</p>
  
  <p><strong>apple -> pen -> book -> bottle &lt;- (scroll back to first index) apple -> pen -> book -> bottle</strong></p>
  
  <p><strong>code:</strong></p>
  
  <pre><code>@objc func scrollAutomatically(_ timer1: Timer) {
  
        if let coll  = CV_Slider {
              for cell in coll.visibleCells {
                  let indexPath: IndexPath? = coll.indexPath(for: cell)
                  if ((indexPath?.row)!  &lt; self.arr_img_Slide.count - 1){
                      let indexPath1: IndexPath?
                      indexPath1 = IndexPath.init(row: (indexPath?.row)! + 1, section: (indexPath?.section)!)
  
                      coll.scrollToItem(at: indexPath1!, at: .centeredHorizontally, animated: true)
                  }
                  else{
                      let indexPath1: IndexPath?
                      indexPath1 = IndexPath.init(row: 0, section: (indexPath?.section)!)
                      coll.scrollToItem(at: indexPath1!, at: .centeredHorizontally, animated: true)
                  }
  
              }
          }
      }
  </code></pre>
  
  <p>Thanks in advance.</p>