为所有可见单元格触发的initialLayoutAttributesForAppearingItemAtIndexPath,而不仅仅是插入的单元格

2024-02-05

有没有人看到这个问题的合适答案?

initialLayoutAttributesForAppearingItemAtIndexPath似乎是所有可见的单元格都被调用,而不仅仅是被插入的单元格。根据苹果自己的文档 https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UICollectionViewLayout_class/Reference/Reference.html:

对于移动的项目,集合视图使用标准方法来检索项目的更新布局属性。对于插入或删除的项目,集合视图会调用一些不同的方法,您应该重写这些方法以提供适当的布局信息

这听起来不像正在发生的事情......其他单元格没有被插入,它们正在被移动,但它正在调用initialLayoutAttributesForAppearingItemAtIndexPath为了那些被感动 too.

我已经看到使用的解决方法prepareForCollectionViewUpdates:跟踪哪些索引路径正在更新并且只更改它们,但这似乎有点奇怪,因为它违背了他们自己的文档。还有其他人找到更好的方法来解决这个问题吗?


I found 马克·波斯佩塞尔 (Mark Pospesel) 的这篇博文 https://mpospese.com/2012/10/25/fixing-circlelayout/提供帮助。
作者还修复了WWDCCircleLayout样品和将其发布到 Github 上 https://github.com/mpospese/CircleLayout/blob/master/CircleLayout/CircleLayout.m.

感兴趣的方法:

- (void)prepareForCollectionViewUpdates:(NSArray *)updateItems
{
    // Keep track of insert and delete index paths
    [super prepareForCollectionViewUpdates:updateItems];

    self.deleteIndexPaths = [NSMutableArray array];
    self.insertIndexPaths = [NSMutableArray array];

    for (UICollectionViewUpdateItem *update in updateItems)
    {
        if (update.updateAction == UICollectionUpdateActionDelete)
        {
            [self.deleteIndexPaths addObject:update.indexPathBeforeUpdate];
        }
        else if (update.updateAction == UICollectionUpdateActionInsert)
        {
            [self.insertIndexPaths addObject:update.indexPathAfterUpdate];
        }
    }
}

- (void)finalizeCollectionViewUpdates
{
    [super finalizeCollectionViewUpdates];
    // release the insert and delete index paths
    self.deleteIndexPaths = nil;
    self.insertIndexPaths = nil;
}

// Note: name of method changed
// Also this gets called for all visible cells (not just the inserted ones) and
// even gets called when deleting cells!
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    // Must call super
    UICollectionViewLayoutAttributes *attributes = [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];

    if ([self.insertIndexPaths containsObject:itemIndexPath])
    {
        // only change attributes on inserted cells
        if (!attributes)
            attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];

        // Configure attributes ...
        attributes.alpha = 0.0;
        attributes.center = CGPointMake(_center.x, _center.y);
    }

    return attributes;
}

// Note: name of method changed
// Also this gets called for all visible cells (not just the deleted ones) and
// even gets called when inserting cells!
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
{
    // So far, calling super hasn't been strictly necessary here, but leaving it in
    // for good measure
    UICollectionViewLayoutAttributes *attributes = [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];

    if ([self.deleteIndexPaths containsObject:itemIndexPath])
    {
        // only change attributes on deleted cells
        if (!attributes)
            attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath];

        // Configure attributes ...
        attributes.alpha = 0.0;
        attributes.center = CGPointMake(_center.x, _center.y);
        attributes.transform3D = CATransform3DMakeScale(0.1, 0.1, 1.0);
    }

    return attributes;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为所有可见单元格触发的initialLayoutAttributesForAppearingItemAtIndexPath,而不仅仅是插入的单元格 的相关文章

  • 如何在触摸时旋转图像并将图像拖动到另一个图像上

    我正在开发一个应用程序 我需要一个包含许多图像的图库 我想要做的是 当用户点击 单击任何图像时 它应该将该图像旋转到 90 度 如果用户将任何图像拖动到任何其他图像的顶部 那么这些图像应该交换它们的位置 或者我们可以说交换 彼此的位置 解释
  • 多个 tableView 单元格中的多个 collectionView

    我有一个tableView其中我有 2 个自定义单元格 在这两个单元格中我有不同的CollectionView 两者的数据源和委托CollectionViews is my ViewController 那么现在我如何检查哪个Collect
  • 创建 Android 智能应用横幅

    Android 设备有类似 iOS 6 智能应用横幅的解决方案吗 这是智能应用横幅的代码 从 Chrome 44 Beta 开始 您可以在 Android 版 Chrome 中推送您的应用程序 您网站上的本机应用程序安装横幅 请看下面的答案
  • 水平滚动 UICollectionView 时捕捉到单元格的中心

    我知道有些人以前问过这个问题 但他们都是关于UITableViews or UIScrollViews我无法得到适合我的可接受的解决方案 我想要的是滚动浏览时的捕捉效果UICollectionView水平 很像 iOS AppStore 中
  • iOS 6 调试控制台不见了?

    当我进行故障排除时 我曾经使用移动 Safari 的 调试控制台 来打印 console log 消息 在 iOS 6 中 Safari 的高级设置中 Web 检查器 取代了 调试控制台 不幸的是 我的公司不允许我将我们正在测试的手机插入我
  • UICollectionView 访问错误 -> UICollectionViewData _setLayoutAttributes:GlobalIndex:

    我使用 UICollectionView 来显示大量图像 其中一批为 32 个 每次到达集合视图的末尾时 我都会加载另一批 32 个图像 并调整 collectionView contentsize width 的大小以接受新项目 通过使用
  • iPhone X 上横向的 UICollectionView

    当 iPhone X 横向使用时 您应该检查 safeAreaInsets 以在左侧和右侧制作适当大的装订线 UITableView 有新的insetsContentViewsToSafeArea属性 默认 true 自动将单元格内容保留在
  • 调试 iOS 应用程序时控制台中的 Webcore NSBeep()?

    当我在 iPhone 上运行 iOS 6 应用程序时 我在控制台中收到这条奇怪的消息 Webcore NSBeep 我在其他帖子中读到 这个 NSBeep 在 iOS 中根本不存在 除此之外 我在我的应用程序中根本没有使用与网络相关的任何内
  • UICollectionReusableView 方法未被调用

    我希望我的部分位于UICollectionView有一个带有图像的标题 我已按照以下步骤操作 在故事板中 分配了一个标题作为我的附件UICollectionView 给它一个标识符 创建了一个子类UICollectionReusableVi
  • 动画 UICollectionView 单元格大小更改并重新定位周围单元格

    Goal 以动画方式改变单元格的高度并重新定位周围的单元格 设想 集合视图中的某些单元格会加载远程图像 最初 这些单元格的大小是静态的 并显示活动指示器 加载图像后 会将其添加到其单元格中 并且更改单元格的高度以适合照片 Notes 我正在
  • XCode 4.5 给我“SenTestingKit/SenTestKit.h”文件未找到,但适用于 4.4.1

    我刚刚安装了 XCode 4 5 它在我现有的项目之一上给了我一个 SenTestingKit SenTestingKit h 文件未找到错误 此错误仅发生在 XCode 4 5 中 但它在 4 4 1 上编译正常 我已经检查过SenTes
  • 如何在 UICollectionView 的节标题中动态添加标签和按钮?

    请帮助我如何水平添加标签和水平添加类似的按钮 但每个按钮应像另一个部分一样在每个标签的下方对齐 这应该在 UICollectionView 的标题中动态发生 因为标签和按钮的数量根据我的数据 我想制作一种 Excel 类型的布局 并在标题中
  • 尝试复制文件时出错

    我正在尝试使用 NSFileManager 将临时文件复制到另一个位置 但是它失败并抱怨其中一个文件不存在 Copy temp file NSError error BOOL exists fileManager fileExistsAtP
  • iOS 10 bug:UICollectionView 收到索引路径不存在的单元格的布局属性

    在 iOS 10 设备上运行我的应用程序时出现以下错误 UICollectionView 收到索引路径不存在的单元格的布局属性 在 iOS 8 和 9 中工作正常 我一直在研究 发现这与使集合视图布局无效有关 我尝试实施该解决方案但没有成功
  • 在 UIViewRepresentable CollectionView(包装的 UICollectionView)中使用 UICollectionViewCell 的 SwiftUI 视图

    我必须更换现有的SwiftUI List的视图UICollectionView 因为应用程序设计已更新 并且新设计对于 SwiftUI 来说非常复杂 因此必须作为自定义实现UICollectionViewFlowLayout 所以视图 现在
  • 根据图像制作具有 UIImageView 高度的 UICollectionViewCells

    我想做一个UICollectionView单元格的宽度是屏幕的宽度 但高度取决于单元格的宽高比UIImageView inside 在我目前的实施中 所有UICollectionViewCell实例是正方形 这不是我想要的 我想以某种方式使
  • 使用 UIActionSheet 更改视图时工具栏项目消失

    当从 a 启动视图时UIActionSheet按钮 通过导航栏后退按钮返回视图后 工具栏虽然仍然可见 但上面没有任何以前的按钮 自从更新到 iOS 6 以来 这个错误就出现了 并且是在模拟器和仅运行 iOS 6 的设备上测试时发生的 如果我
  • 无法启动“”无法获取进程 的任务?

    使用 Xcode 4 5 2 并为 iOS4 或更高版本构建时 在为我的设备 4s 上的 iOS 6 0 1 构建时收到此消息 我关闭该对话框 然后在我的设备上重新启动该应用程序 该应用程序似乎可以正常工作 我是 iOS 开发新手 所以如果
  • iOS 6 中已弃用的代码回退到 iOS 5

    我有这个自定义后退按钮 IBAction backToMenu id sender self presentingViewController dismissModalViewControllerAnimated YES 在 iOS 6 模
  • iOS 6 中捕捉全景的库 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 在iOS中有很多方法和库来显示全景图片 虽然内置相机中有全景功能 但无法在应用程序中使用它 有没有可以用来捕获全景图像的库 Thanks

随机推荐