UICollectionvView会创建不需要的页面偏移

时间:2014-09-15 07:12:54

标签: ios objective-c

我有这个UICollectionView水平滚动,其中单元格大小与屏幕相同, 第一个单元格位于正确的位置,但是当我滚动到下一页(>>右)时,下一个单元格从页面的小偏移开始(左偏移)。现在,当我继续滚动时,这个左偏移正在增加。所以在3页之后,单元格在屏幕中间开始。我无法弄清楚为什么会有它。

self.collectionView.delegate=self;
self.collectionView.dataSource=self;
self.collectionView.backgroundColor=[UIColor clearColor];

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
 flowLayout.minimumInteritemSpacing=0;
flowLayout.minimumLineSpacing=0;

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
         int margins=0;
    return UIEdgeInsetsMake(margins, margins, margins, margins);
}


- (CGSize)collectionView:(UICollectionView *)collectionView
                      layout:(UICollectionViewLayout*)collectionViewLayout
      sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
       CGSize size=[UIScreen mainScreen].bounds.size;
       return size;
}

1 个答案:

答案 0 :(得分:0)

解决。 在代码中设置单元格之间的最小间距是不够的。你必须在故事板中将它更改为0,而不是默认10.我的问题是我在单元格之间有间距,因此单元格从屏幕偏移开始。

相关问题