Skip to content

Instantly share code, notes, and snippets.

@wassim93
Last active September 28, 2022 10:07
Show Gist options
  • Select an option

  • Save wassim93/4611f509618986b831a40eb38064451a to your computer and use it in GitHub Desktop.

Select an option

Save wassim93/4611f509618986b831a40eb38064451a to your computer and use it in GitHub Desktop.

Revisions

  1. wassim93 revised this gist Jun 3, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions automatic scroll collectionview.swift
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    @IBOutlet weak var collectionView: UICollectionView!
    // fill your datasource array with data
    var datasource: [] = []


    override func viewDidLoad() {
    super.viewDidLoad()
  2. wassim93 revised this gist Jun 3, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions automatic scroll collectionview.swift
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    @IBOutlet weak var collectionView: UICollectionView!

    override func viewDidLoad() {
    super.viewDidLoad()

    startTimer()
    }



    func startTimer() {

    let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.scrollAutomatically), userInfo: nil, repeats: true)
    let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.scrollAutomatically), userInfo: nil, repeats: true)

    }


  3. wassim93 renamed this gist Jun 3, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. wassim93 created this gist May 11, 2020.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    override func viewDidLoad() {
    super.viewDidLoad()

    startTimer()
    }



    func startTimer() {

    let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.scrollAutomatically), userInfo: nil, repeats: true)
    }


    @objc func scrollAutomatically(_ timer1: Timer) {

    if let coll = collectionView {
    for cell in coll.visibleCells {
    let indexPath: IndexPath? = coll.indexPath(for: cell)
    if ((indexPath?.row)! < datasource.count - 1){
    let indexPath1: IndexPath?
    indexPath1 = IndexPath.init(row: (indexPath?.row)! + 1, section: (indexPath?.section)!)

    coll.scrollToItem(at: indexPath1!, at: .right, animated: true)
    }
    else{
    let indexPath1: IndexPath?
    indexPath1 = IndexPath.init(row: 0, section: (indexPath?.section)!)
    coll.scrollToItem(at: indexPath1!, at: .left, animated: true)
    }

    }
    }
    }