[英]iOS7 UICollectionView how to move a single cell to a different section with animation?
我有一個應用程序,其中包含用戶可以閱讀的文章列表。 一旦用戶點擊了一篇文章,我想將其呈現給用戶,然后設置動畫,將代表該文章的單元格移動到另一個代表已閱讀文章的集合視圖部分:
Unread | Read
0 0 0 0 | X X
下面的代碼使所有單元格都重新加載,看起來它們全部都閃爍着背景色。 我是否可以通過動畫方式將一個單元格從集合視圖的一個部分移動到另一部分?
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if([collectionView isEqual:self.largeCollectionView])
{
//position the tapped image at the end and animate reload
UIImage* image = largeImages[indexPath.row];
[largeImages removeObjectAtIndex:indexPath.row];
[largeImages addObject:image];
}
[collectionView performBatchUpdates:^{
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:^(BOOL finished) {
}];
}
您是否看過-moveItemAtIndexPath:toIndexPath:
? 聽起來這正是您所需要的。
您似乎正在更改支持集合視圖的數據,然后依靠-reloadSections:
更新UI。 毫不奇怪,這會重新加載該節中的每個單元。 由於您確切知道已執行了哪些更改,因此至少可以使用-deleteItemsAtIndexPaths:
和-insertItemsAtIndexPaths:
來指示刪除和重新插入該圖像的確切位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.