I'm using a horizontal collection view to display various quotes which users can swipe to scroll through. It works fine, but the scroll is more like one long continuous scroll (like Instagram). I would like to change this to have each quote stop in the center of the screen and then the user to swipe again to go to the next quote (more like TikToc). How can I make this happen? I'm new to coding, so I'm not sure if there is a function for this. I tried the func ScrollToitem but don't know how to get it to implement this behavior.
import UIKit
class mainViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var checkcollectionview: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
checkcollectionview.dataSource = self
checkcollectionview.delegate = self
checkcollectionview.collectionViewLayout = UICollectionViewFlowLayout()
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
self.checkcollectionview.collectionViewLayout = layout
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return quotes.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = checkcollectionview.dequeueReusableCell(withReuseIdentifier: "check", for: indexPath) as! checkCollectionViewCell
cell.setup(with: quotes[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 700, height: 200)
}
}