3

I have horizontal scrolling set up now I would like for it to sort of scroll/snap one cell at a time when scrolling side to side.

Could someone shed some light? Here's the code I have so far:

- (void)viewDidLoad
{
    [super viewDidLoad];
}

#pragma mark - UICollectionView Datasource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

#pragma mark - UICollectionViewDelegateFlowLayout

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(50, 20, 50, 20);
}
goo
  • 2,230
  • 4
  • 32
  • 53
  • possible duplicate of [UICollectionView with paging - setting page width](http://stackoverflow.com/questions/20496850/uicollectionview-with-paging-setting-page-width) – diclophis Jan 22 '14 at 23:34

1 Answers1

15

[collectionView setPagingEnabled:YES]; might do the trick?

http://adoptioncurve.net/archives/2013/04/creating-a-paged-photo-gallery-with-a-uicollectionview/

diclophis
  • 2,444
  • 1
  • 17
  • 10