Search code examples
swiftuicollectionviewscrollviewuipagecontrol

How to get ScrollView for Two UICollectionView in swift?


As i have used this code to get current page index in pageControl. But this function can't distinguish if scrollView is for Which collectionView.

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if collectionView == self.brandCollectionView {
            brandPageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
        } else {
            brandPageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
        }
    }

Solution

  • Solution is working :

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
           if scrollView == self.collectionView {
               //code for this scrollView1
            } else {
                 //code for this scrollView2
            }
        }