水平UICollectionView顶部的奇数空白区域

时间:2016-03-05 20:20:57

标签: ios uicollectionview uicollectionviewlayout

我有一个空格,我无法找到UICollectionView顶部的原因。

我在故事板中禁用了标题,所以我不相信它。

这是一张图片:

enter image description here

CollectionView的代码

- (void)setupCollectionView
{
  [self.scoreCollectionView setDataSource:self];
  [self.scoreCollectionView setDelegate:self];
  [self.scoreCollectionView registerClass:[AAScoreCell class] forCellWithReuseIdentifier:cellIndentifier];
}

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

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  AAScoreCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifier forIndexPath:indexPath];

  if (_selectedIndexPath) {
    [cell showSelection:[indexPath isEqual:_selectedIndexPath]];
  }

  return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
  AAScoreCell *cell = (AAScoreCell*)[collectionView cellForItemAtIndexPath:indexPath];
  [cell showSelection:![indexPath isEqual:_selectedIndexPath]];
  _selectedIndexPath = [indexPath isEqual:_selectedIndexPath] ? nil : indexPath;
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
  AAScoreCell *cell = (AAScoreCell*)[collectionView cellForItemAtIndexPath:indexPath];
  [cell showSelection:NO];
  _selectedIndexPath = nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
  return CGSizeMake(self.scoreCollectionView.frame.size.height-50, self.scoreCollectionView.frame.size.height-50);
}

1 个答案:

答案 0 :(得分:1)

不会假装我明白为什么但是:

[self setAutomaticallyAdjustsScrollViewInsets:NO];

为我解决了这个问题