如何在didselect上展开collectionview单元以显示更多信息?

我想animation我的collectionview单元格,以便当我触摸它时,一个mapview从它下面滑出,基本上通过将它下面的单元格向下推动,扩展到空间中。 我尝试使用这个: UICollectionView:animation单元大小更改select ,但无法让它正常工作。

在这里,我试过。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [((FeedCell *)[collectionView cellForItemAtIndexPath:indexPath]) setIsSelected:YES]; [collectionView.collectionViewLayout invalidateLayout]; __weak FeedCell *cell = (FeedCell *)[self.photoCollectionView cellForItemAtIndexPath:indexPath]; // Avoid retain cycles void (^animateChangeWidth)() = ^() { CGRect frame = cell.frame; frame.size = CGSizeMake(frame.size.width, 420); cell.frame = frame; }; // Animate [UIView transitionWithView:[collectionView cellForItemAtIndexPath:indexPath] duration:0.5f options: UIViewAnimationOptionCurveLinear animations:animateChangeWidth completion:nil]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if(((FeedCell *)[self.photoCollectionView cellForItemAtIndexPath:indexPath]).isSelected == YES){ return CGSizeMake(320, 420); } return CGSizeMake(320, 320); } 

我有一个自定义的CollectionView单元格,它有一个isSelected属性。 我不知道我应该为单元格的xib做些什么(无论是将地图视图放在那里,CGSize是选定的大小还是取消选定的大小等)。任何帮助真的会被赞赏!

我正在尝试做与你一样的事情,并在我的search中find你的问题。 看来,你有一个很好的解决scheme(至less在我的经验不足)。 什么不适合你? 我通过几乎逐字地复制你的代码来完成我想要的工作。 我改变了一些东西,但在进行更改之前没有testing代码。 以下是我在didSelectItemAtIndexPath方法中为我工作的内容:

 __weak MyCell *cell = (MyCell*)[collectionView cellForItemAtIndexPath:indexPath]; [cell setSelected:YES]; [collectionView.collectionViewLayout invalidateLayout]; void (^animateChangeWidth)() = ^() { CGRect frame = cell.frame; frame.size = CGSizeMake(frame.size.width, 340.0f); cell.frame = frame; }; // Animate [UIView transitionWithView:cell duration:0.5f options: UIViewAnimationOptionCurveEaseInOut animations:animateChangeWidth completion:nil]; 

我也有重写collectionView:layout:sizeForItemAtIndexPath所以我假设你也是这样。

对不起,我不能更具体。 如果你说什么不起作用,这将有所帮助。