設定contentInsetsは、最初と最後のセルの周りにいくつかの余分なスペースを与える必要があります
[collectionView scrollToItemAtIndexPath:selectedItemPath
atScrollPosition:UICollectionViewScrollPositionCenteredVertically
animated:YES];
それは正しいスクロール位置を渡すことが重要です:UICollectionViewScrollPositionCenteredVertically
これをタップされたアイテムを適切にセンタリングすべきです。
EDIT
それは本当に奇妙だが、コレクションビューメソッドにUIEdgeInsetsを設定した後scrollToItemAtIndexPathは正しく動作しませんので、私はいくつかの変更を行います。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat collectionViewHeight = CGRectGetHeight(self.collectionView.frame);
[collectionView setContentInset:UIEdgeInsetsMake(collectionViewHeight/2, 0, collectionViewHeight/2, 0)];
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
CGPoint offset = CGPointMake(0, cell.center.y - collectionViewHeight/2);
[collectionView setContentOffset:offset animated:YES];
}
それは私のために正常に動作します。
私の編集した答えをチェックしてください、私はそれにいくつかの変更を加えました – Mikhail