将选定的UICollectionView Cell移动到collectionview的中心

时间:2014-09-16 10:31:01

标签: ios objective-c uicollectionviewcell uicollectionviewlayout

我有如下的collectionview单元格。中间行应该始终可见,另外两个应该总是看到一半。但是,当我点击顶部或底部的任何行时,它应该占据中间单元格位置。我该怎么做?

我在下面累了,但它确实使选定的细胞可见,但不会占据中心。

 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
      [colctnView_gallery scrollRectToVisible:[[colctnView_gallery   layoutAttributesForItemAtIndexPath:indexPath] frame] animated:YES];
}

enter image description here如下:

1 个答案:

答案 0 :(得分:0)

尝试设置集合视图的ContentInset

[colctnView_gallery setContentInset:UIEdgeInsetsMake(top, left, bottom, right)];

leftright设置为0. topbottom应该等于您的(yourCollectionView的剖面高度+间距)/ 2,或者如果您只是使用1个部分topbottom应该等于(yourCollectionView的单元格高度+间距)/ 2。

相关问题