【问题标题】:How to expand collectionview cell on didselect to show more info?如何在 didselect 上展开 collectionview 单元格以显示更多信息?
【发布时间】:2013-09-27 18:59:44
【问题描述】:

我想为我的collectionview单元格设置动画,这样当我触摸它时,一个mapview会从它下面滑出并基本上扩展到空间中,方法是将它下面的单元格向下推一点。我尝试使用这个:UICollectionView: Animate cell size change on selection,但无法让它正常工作。

这是我尝试过的。

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

【问题讨论】:

  • 您找到解决方案了吗?
  • 不,很遗憾没有。但我没有尝试太久,我最终只是改变了我计划制作的界面。

标签: ios objective-c uicollectionview uicollectionviewcell uicollectionviewlayout


【解决方案1】:

我正在尝试和您做同样的事情,并在我的搜索中找到了您的问题。看来您有一个很好的解决方案(至少在我没有经验的情况下)。什么不适合你?我通过几乎逐字复制您的代码来完成我想做的事情。我更改了一些东西,但在进行更改之前没有测试代码。这是我在 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,所以我认为这也适用于您。

抱歉,我不能说得更具体。如果你说它不起作用会有所帮助。

【讨论】:

  • 感谢您的反对。可能是评论解释出了什么问题或提供更好的解决方案?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-14
  • 1970-01-01
  • 1970-01-01
  • 2022-12-10
  • 1970-01-01
  • 2013-11-02
相关资源
最近更新 更多