1

我想要動畫我的collectionview單元格,以便當我觸摸它時,mapview會從其下面滑出,並基本上通過將它下面的單元格向下推一點而擴展到空間中。我試着用這個:UICollectionView: Animate cell size change on selection,但無法讓它正常工作。如何展開didselect上的collectionview單元以顯示更多信息?

在這裏,我試過。

- (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是選定的大小還是取消選定的大小等)。真的很感謝任何幫助!

+0

您是否曾經爲此找到過解決方案? – Andrespch

+0

不幸的不是。但我沒有嘗試太久,最後我改變了我打算製作的界面。 – mjmayank

回答

-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:佈局:sizeForItemAtIndexPath所以我認爲是爲你工作爲好。

對不起,我不能更具體。如果你說它沒有工作,它會有所幫助。

+0

感謝您的投票。也許是評論解釋什麼是錯的或提供更好的解決方案? –

相關問題