I am currently using a CollectionView within my UIViewController that scrolls horizontally through a variable number of cells (There are 3 cells visible on the display at a time). I want it so that when the user finishes scrolling that the view smoothly snaps/pulls to the cell closest to the center of the screen. Does anyone have suggestions on how this could be done?
Asked
Active
Viewed 2,337 times
0
-
Hi, please take a look at this question, looks similar to what you want to achieve https://stackoverflow.com/questions/33855945/uicollectionview-snap-onto-cell-when-scrolling-horizontally – Alexander Tkachenko Nov 17 '17 at 14:18
-
P.S. Accepted answer is really great, I used the same approach – Alexander Tkachenko Nov 17 '17 at 14:20
-
Hi Alexander, thanks for you fast reply! I did see that question but I was unable to get the accepted answer working. I am rather new to swift and I couldn't figure out how to implement Mark Bourke's solution. Do you have any suggestions? – bcupp Nov 17 '17 at 14:30
-
What were you having trouble implementing in his solution? – Nevin Jethmalani Nov 17 '17 at 14:55
-
Honestly I wasn't sure where to start in using it on a specific UICollectionView. I created a file to store the SnappingCollectionViewLayout subclass, but I wasn't sure in what context I was supposed to use the class within my UIViewController that contained the UICollectionView. I am sure it is a simple solution, my mind is just coming up blank. – bcupp Nov 17 '17 at 15:04
-
After you create class SnappingCollectionViewLayout, If you use storyboard or xib for your view controller, then just set the class name for your collection view layout in the Utilities(usually on the right side) tab from XCode. http://joxi.net/p273pqs0YMNX27.jpg – Alexander Tkachenko Nov 17 '17 at 15:30
-
I knew I was overlooking something simple! Wonderful. I will report back once I have had the chance to implment it. Thank you both! – bcupp Nov 17 '17 at 15:36
-
Thank you for that screenshot, that did the trick. – bcupp Nov 18 '17 at 21:02