如何在 didselect 上展开 collectionview 单元格以显示更多信息? [英] How to expand collectionview cell on didselect to show more info?

查看:38
本文介绍了如何在 didselect 上展开 collectionview 单元格以显示更多信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 collectionview cell 设置动画,这样当我触摸它时,mapview 从它下面滑出并基本上扩展到空间中,方法是将它下面的 cell 向下推一点.我试过用这个:UICollectionView:选择时改变单元格大小的动画,但无法使其正常工作.

I want to animate my collectionview cell so that when I touch it, a mapview slides out from underneath it and basically expands into the space, by pushing the cell underneath it down a little bit. I tried using this: UICollectionView: Animate cell size change on selection, but was unable to get it to work properly.

这是我尝试过的.

- (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 设置为选定的大小或取消选择的大小等)任何帮助将不胜感激!

I have a custom CollectionView cell and it has a property for isSelected. I'm not sure what I should do for the xib of the cell (whether to put the map view in there, have the CGSize be the selected size or deselected size, etc.) Any help would really be appreciated!

推荐答案

我正在尝试和您做同样的事情,并在我的搜索中找到了您的问题.看来您有一个很好的解决方案(至少在我没有经验的情况下).什么对你不起作用?我几乎是逐字复制你的代码,让它做我想做的事.我更改了一些内容,但在进行更改之前没有测试代码.这是我在 didSelectItemAtIndexPath 方法中对我有用的东西:

I am trying to do the same thing as you and found your question in my search. It appears that you have a pretty good solution (at least in my inexperienced opinion). What isn't working for you? I got it to do what I wanted by copying your code almost verbatim. I changed a few things, but didn't test the code before making the changes. Here is what I have that works for me in my didSelectItemAtIndexPath method:

__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 所以我认为这也适用于你.

I also have overridden collectionView:layout:sizeForItemAtIndexPath so I assume that is working for you as well.

对不起,我不能说得更具体了.如果你说它不起作用,它会有所帮助.

Sorry I can't be more specific. It would help if you said what about it wasn't working.

这篇关于如何在 didselect 上展开 collectionview 单元格以显示更多信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆