0

I have a scrollView(only horizontal scrolling) in which two collection views and want that if it is dragged/Swiped upto >= mid of screen then it should scroll forward i.e right side (show 2nd collection view) else it should be in left side(show first collection view). It should not stay half scrolled either full or none. How can i make this possible?

Abhishek Thapliyal
  • 3,497
  • 6
  • 30
  • 69

1 Answers1

0

To achieve a scroll snap, you want to use this UIScrollViewDelegate method:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)

You'll want to set the following within this method.

targetContentOffset.pointee.x = 

Here's a tutorial link that may help explain.

Or just convert this ObjC SO answer to swift and change from vertical snapping to horizontal as it describes.

Smartcat
  • 2,834
  • 1
  • 13
  • 25