gpt4 book ai didi

ios - UICollectionViewCell 翻转并在点击时增长

转载 作者:技术小花猫 更新时间:2023-10-29 11:03:09 25 4
gpt4 key购买 nike

如何实现带有翻转和增长以在点击时显示模态视图的 UICollectionViewCell 的动画?

最佳答案

这是我在另一个项目中使用的,效果很好:

- (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: 消息调用用于防止单元格在其他单元格后面设置动画
  • 我们使用在 Controller 中声明的两个属性:selectedCellDefaultFrameselectedCellDefaultTransform 来保存单元格的默认状态并在取消选择时重新初始化它
  • 取消选择时,我们调用UICollectionViewreloadItemsAtIndexPaths:方法来确保位置的重置完全完成

如果您对此有任何问题,请告诉我。

祝你好运

关于ios - UICollectionViewCell 翻转并在点击时增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13765006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com