我试图找出一种方法来动画删除UICollectionViewCell
类似于 iOS 7 中的跳板。被删除的单元格应该缩小成虚无,剩余的单元格应该滑过以填充它的位置(滑动是重要的部分)。我努力了:
• 将每个单元格的框架设置为前一个单元格的框架,如下所示:
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
CGRect rect = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i - 1 inSection:0]].frame;
[UIView animateWithDuration:0.2 animations:^{
cell.frame = rect;
}];
但这不起作用,因为细胞根本没有移动。
• 以下两项:
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
和
[UIView animateWithDuration:0.2 animations:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
}];
但是这些使细胞交叉淡化到它们所需的位置,而不是滑动。
我还发现了这个项目,它使用以下内容:
for (int i = index+1; i<[items count]; i++) {
SEMenuItem *item = [items objectAtIndex:i];
[UIView animateWithDuration:0.2 animations:^{
if (i < index + remainingNumberOfItemsInPage) {
int intVal = item.frame.origin.x;
if (intVal %3== 0)
[item setFrame:CGRectMake(item.frame.origin.x+2*item.frame.size.width, item.frame.origin.y-item.frame.size.height-5, item.frame.size.width, item.frame.size.height)];
else
[item setFrame:CGRectMake(item.frame.origin.x-item.frame.size.width, item.frame.origin.y, item.frame.size.width, item.frame.size.height)];
}
[item updateTag:item.tag-1];
}];
}
但是,它不在 a 中UICollectionView
,所以它对我没有帮助。
注意:我在 iPad 上执行此操作,以防万一它对您很重要。
有任何想法吗?