相关疑难解决方法(0)

UICollectionView moveItemAtIndexPath:toIndexPath:不在屏幕上发出移动项目

我正在尝试在iOS 6上的UICollectionView中重新排序项目的动画.

我写了这段代码:

    NSMutableDictionary *from = [NSMutableDictionary dictionaryWithCapacity:self.count];
    for (int ii = 0; ii < self.count; ii++) {
        MyItem item = [self getItemAtIndex:(NSInteger)ii];
        [from setObject:[NSNumber numberWithInt:ii] forKey:[NSNumber numberWithInt:item.id]];
    }

    [self sort];

    [self.collectionView performBatchUpdates:^{
        for (int ii = 0; ii < self.count; ii++) {
            MyItem item = [self getItemAtIndex:(NSInteger)ii];
            NSNumber *prevPos = (NSNumber *)[from objectForKey:[NSNumber numberWithInt:item.id]];
            if ([prevPos intValue] != ii) {
                NSIndexPath *from = [NSIndexPath indexPathForItem:prevPos.intValue inSection:0];
                NSIndexPath *to = [NSIndexPath indexPathForItem:ii inSection:0];
                [self.collectionView moveItemAtIndexPath:from toIndexPath:to];
            }
        }
    } completion:nil]; …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewcell

9
推荐指数
1
解决办法
1万
查看次数

UICollectionView单元格展开动画问题

我遇到一个问题,我的 UICollectionView 使用 UICollectionViewCompositionalLayout + Diffable 数据源不允许我平滑地设置垂直单元格扩展的动画。我有一个类似于 UITableView 的全角单元格列,我试图展开单元格以在选择单元格时显示截断的文本。

这在没有动画的情况下工作得很好,但是当我尝试对其进行动画处理时,如果扩展单元格下方的单元格将最终位置超出屏幕边界,则我无法让它看起来流畅,因为单元格将立即消失而不是被动画“推”向下。该问题可以在链接的 gif 中看到https://i.stack.imgur.com/Hd5Dx.jpg

如果扩展单元格下方的单元格的最终位置位于屏幕边界内,则不会出现此问题,如下所示:https: //i.stack.imgur.com/g0QK9.jpg

我发现一个较旧的问题似乎有类似的问题:UICollectionView animating cell size change Causes undesirable behavior

那里的答案很旧,对我没有帮助,因为我没有使用 Flow Layout,也没有使用 Obj-C。

我看到许多应用程序(例如 Instagram,当图像标题具有“查看更多”时)可以使用 UICollectionView 实现所需的结果,而不会出现任何动画问题,因此我认为这一定是可能的。

uikit ios uicollectionview swift uicollectionviewcompositionallayout

3
推荐指数
1
解决办法
3122
查看次数