Search code examples
swiftscrolluicollectionviewuiscrollviewuiscrollviewdelegate

How can i get how to scrolled it is in uicollectionView


I’m using uicollectionview in storyboard.

When uicollectionview scroll down i want get how scrolled down In pixels

For example, if i swipe one finger, return 200 pixels.

Is it possible?


Solution

  • you can get the scroll event with UIScrollViewDelegate and

    func scrollViewDidScroll(_ scrollView: UIScrollView) { }
    

    Now, you can have the scroll position with scrollView.contentOffset it's a CGPoint, so with a conversion (point to pixel) you should get the numbers of Pixel.

    scrollView.contentOffset.y * UIScreen.main.scale
    

    This should works.