![](/img/trans.png)
[英]CollectionView `DidSelect` method is being called but not pushing the next VC, how to fix it?
[英]How to expand collectionview cell on didselect to show more info?
我想为我的collectionview单元设置动画,以便当我触摸它时,mapview会从其下方滑出,并通过将其下方的单元向下一点一点而基本上扩展到空间中。 我尝试使用以下方法: UICollectionView:动画化选定单元格的大小 ,但无法使其正常工作。
这是我尝试过的。
- (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设置为选定的大小或取消选定的大小,等等。)任何帮助将不胜感激!
我正尝试与您做同样的事情,并在搜索中找到了您的问题。 看来您有一个不错的解决方案(至少以我的经验)。 什么对您不起作用? 通过几乎逐字复制您的代码,我可以执行所需的操作。 我做了一些更改,但是在进行更改之前没有测试代码。 这是我在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,所以我认为这对您也很有效。
抱歉,我不能更具体。 如果您说那没有用,那会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.