解决方法
这是我在另一个项目中使用的,它运行良好:
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; if (cell.selected) { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; [UIView transitionWithView:cell duration:0.2 options:UIViewAnimationoptionTransitionFlipFromLeft animations:^{ [cell setFrame:self.selectedCellDefaultFrame]; cell.transform = self.selectedCellDefaultTransform; } completion:^(BOOL finished) { self.selectedCellDefaultFrame = CGRectZero; [collectionView reloadItemsAtIndexPaths:@[indexPath]]; }]; return NO; } else { return YES; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; [cell.superview bringSubviewToFront:cell]; self.selectedCellDefaultFrame = cell.frame; self.selectedCellDefaultTransform = cell.transform; [UIView transitionWithView:cell duration:0.2 options:UIViewAnimationoptionTransitionFlipFromright animations:^{ [cell setFrame:collectionView.bounds]; cell.transform = CGAffineTransformMakeRotation(0.0); } completion:^(BOOL finished) {}]; }
不同的东西在这里:
> bringSubviewToFront:消息调用用于防止单元格在其他单元格之后动画化
>我们使用控制器中声明的两个属性:selectedCellDefaultFrameand selectedCellDefaultTransform来保存单元格的默认状态,并在取消选择时重新初始化
>当取消选择时,我们调用UICollectionView的reloadItemsAtIndexPaths:方法来确保位置的重置完全完成
如果您有任何麻烦,请告诉我们.
祝你好运,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。