簡體   English   中英

如何在didselect上展開collectionview單元以顯示更多信息?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM