UICollectionView Horizontal Scrolling

I am using UICollectionView in my iOS application. I have it so that each cell is the width of the screen, and I want to have it, so when it scrolls horizontally, it is fixed on the visible cell and moves it to the center of the screen. In the code below, I only work for the first cell. I do not understand how to make this work for any cell that the user sees.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ int index = 0; for (TextCell * t in [_tabBarCollectionView visibleCells]) { if ((t.center.x>0)&&(t.center.x<[[UIScreen mainScreen]bounds].size.width)) { [_tabBarCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES]; break; } index++; } } 
+4
source share
1 answer

You can enable paging to represent the collection, and it will have this effect. Go to the xib file or storyboard with the addition of a collection and enable swapping for your properties.

+4
source

All Articles