【问题标题】:How to get ScrollView for Two UICollectionView in swift?如何快速获取两个 UICollectionView 的 ScrollView?
【发布时间】:2020-07-10 14:46:32
【问题描述】:

因为我已使用此代码在 pageControl 中获取当前页面索引。但是这个函数无法区分scrollView是针对哪个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)
        }
    }

【问题讨论】:

    标签: swift uicollectionview scrollview uipagecontrol


    【解决方案1】:

    解决方案有效:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多