【发布时间】:2014-09-10 15:46:39
【问题描述】:
我正在尝试找出一种方法来动画删除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]];
}];
但这些会使细胞交叉淡化到所需的位置,而不是滑动。
我还找到了this project,它使用以下内容:
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];
}];
}
但是,它不在UICollectionView 中,所以它对我没有帮助。
注意:我在 iPad 上执行此操作,以防万一对您很重要。
有什么想法吗?
【问题讨论】:
-
我希望我能发布一个完整的答案,因为我做过这样的事情。只需将单元格的大小设置为
CGSizeZero,它的原点就是在以下方法developer.apple.com/library/ios/documentation/uikit/reference/…中单元格的center之前的点:
标签: ios objective-c ios7 uicollectionview springboard