gpt4 book ai didi

iphone - 如何将(动画)UICollectionView 单元格移入和移出圆形 [PICS]

转载 作者:行者123 更新时间:2023-11-29 13:08:23 25 4
gpt4 key购买 nike

我正在使用自定义布局来定位我的 UICollectionViewCells:

enter image description here

这很好用。现在,当我按下左下角的按钮时,我想让所有单元格动画地返回到 View 的中心,如下所示:

enter image description here

我有点像这个工作,但它根本没有动画。它只是以那种方式流行起来。这是我用于重新加载操作的代码:

- (IBAction)animate:(id)sender {
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
}

在我的布局类中,我有一个标志,每次调用 prepareLayout 时我都会翻转它来调整 layoutAttributesForItemAtIndexPath 中单元格的中心,如下所示:

- (UICollectionViewLayoutAttributes*) layoutAttributesForItemAtIndexPath:(NSIndexPath *)path {
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:path];
attributes.size = CGSizeMake(ITEM_SIZEw, ITEM_SIZEh);

if (self.isCircle) {
attributes.center = CGPointMake(_center.x +_radius *
cosf(2 * path.item * M_PI / _cellCount),
_center.y + _radius *
sinf(2 * path.item * M_PI/ _cellCount));
} else {
attributes.center = [self collectionView].center;
}

return attributes;
}

如何让单元格移动回到 View 中心?

最佳答案

好吧,我找到了答案。制作不同的布局并使用动画切换到它:

[self.collectionView setCollectionViewLayout:home animated:YES];

关于iphone - 如何将(动画)UICollectionView 单元格移入和移出圆形 [PICS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17980316/

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