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?
Asked
Active
Viewed 485 times
0
-
Is right side means bottom ? Can you please clear this thing. – Aditya Srivastava Aug 13 '17 at 05:55
-
@AdityaSrivastava : i have update the question – Abhishek Thapliyal Aug 13 '17 at 05:57
-
Still not clear. – Smartcat Aug 13 '17 at 06:01
-
@Smartcat : i have update the question – Abhishek Thapliyal Aug 13 '17 at 06:02
1 Answers
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