我想要動畫我的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是選定的大小還是取消選定的大小等)。真的很感謝任何幫助!
您是否曾經爲此找到過解決方案? – Andrespch
不幸的不是。但我沒有嘗試太久,最後我改變了我打算製作的界面。 – mjmayank