UICollectionView current visible cell index

后端 未结 16 1426
难免孤独
难免孤独 2020-11-29 16:52

I am using UICollectionView first time in my iPad application. I have set UICollectionView such that its size and cell size is same, means only onc

16条回答
  •  失恋的感觉
    2020-11-29 17:15

    Swift 3 & Swift 4:

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
       var visibleRect = CGRect()
    
       visibleRect.origin = collectionView.contentOffset
       visibleRect.size = collectionView.bounds.size
    
       let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
    
       guard let indexPath = collectionView.indexPathForItem(at: visiblePoint) else { return } 
    
       print(indexPath[1])
    }
    

    If you want to show actual number than you can add +1

提交回复
热议问题