gpt4 book ai didi

ios - UICollectionView 重新排序

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

iOS9 为 UICollectionView 实现了一个很好的重新排序功能。

在我的 CollectionViewController 中,我实现了以下代码以使其正常工作:

- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{
_cells[sourceIndexPath.row][1] = [NSString stringWithFormat:@"%li", (long)destinationIndexPath.row];
_cells[destinationIndexPath.row][1] = [NSString stringWithFormat:@"%li", (long)sourceIndexPath.row];
[self saveCellorder];
}

'cells' 数组只是用来保存 View 中单元格的顺序

--

现在我的问题/问题:

我的 CollectionView 中有 2 个不同大小的单元格,当我将一个小单元格拖到一个小单元格上时,它们会改变它们的位置,一切正常。当我将一个大单元格拖到一个大单元格上时,也会发生同样的情况。

但是当我将一个小单元格拖到一个大单元格上时,大单元格变小而小单元格变大。我怎样才能防止细胞改变它们的大小?

最佳答案

我想,您已经委托(delegate)方法 -collectionView:layout:sizeForItemAtIndexPath: 实现了。严格来说,此方法返回的不是单元格 的大小。它返回指定位置单元格的大小。因此,您应该捕获时机,当 Collection View 顺序更改并以某种方式响应它时,告诉 -collectionView:layout:sizeForItemAtIndexPath: 返回正确的大小。

或者,您可以简单地实现自调整 Collection View 单元格。查看 WWDC 2014“表和 Collection View 的新增功能”。这很容易 Amazing©

有关自动调整单元格的更多信息:SO answer

关于ios - UICollectionView 重新排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32736568/

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