iOS:一次滚动一个单元格

时间:2014-01-22 23:32:09

标签: ios objective-c uicollectionview uicollectionviewcell

我已经设置了水平滚动功能,我希望它能够在左右滚动的同时滚动/捕捉一个单元格。

有人可以解决一些问题吗?这是我到目前为止的代码:

- (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);
}

1 个答案:

答案 0 :(得分:15)

[collectionView setPagingEnabled:YES];可以解决这个问题吗?

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