- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经实现了我自己的从 UICollectionViewLayout 子类化的集合 View 布局。在 prepare
我计算和缓存布局属性。
在 layoutAttributesForElementsInRect
我过滤掉那些不正确的:
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return itemAttributesCache.filter { $0.frame.intersects(rect) }
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
将为
layoutAttributesForElementsInRect
中返回的每个索引路径调用
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return itemAttributesCache
}
cellForItemAt
方法仍然只为可见矩形内的属性调用。
cellForItemAt
对于所有返回的属性?
最佳答案
是的,这是集合 View 的预期行为。在 UICollectionViewLayout
的文档中苹果说(强调):
The job of a layout object is to determine the placement of cells, supplementary views, and decoration views inside the collection view’s bounds and to report that information to the collection view when asked.
The collection view asks its layout object to provide layout information for these elements at many different times. Every cell and view that appears on screen is positioned using information from the layout object.
prepare
中。函数,你必须在
layoutAttributesForElementsInRect
中实现一些逻辑用于计算布局属性。在这种情况下,您使用可见的 rect 参数仅计算将在屏幕中可见的单元格和 View 的属性值。
cellForItemAt
对于所有返回的属性,我不确定这样做的值(value)是什么,因为它只会使用其中的几个。实现这一目标的唯一方法是拥有一个与您正在显示的内容大小相同的集合 View ,以便所有单元格都被视为可见。但是,这样做首先使使用集合 View 的意义无效,因为单元格不会被重用,也不会滚动。如果你想用集合 View 项修复一些奇怪的动画,这不是要走的路。
关于ios - UICollectionViewLayout.layoutAttributesForElementsInRect 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59357522/
我完全不知道为什么会这样,但无论出于何种原因,我正在使用的 Collection View 正在无限循环 [UICollectionViewData layoutAttributesForElemen
我已经实现了我自己的从 UICollectionViewLayout 子类化的集合 View 布局。在 prepare我计算和缓存布局属性。 在 layoutAttributesForElements
在我的使用中 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect 在自定义布局子类中,我只看到大部分是 1024 的倍数的矩形坐标值
我想创建一个垂直无限滚动,在阅读了这么多教程后我明白我需要子类化 UICollectionViewFlowLayout。问题是我不完全明白该怎么做。 我试过以下方法:1. 创建了一个新类 newVie
此代码用于 swift 2.3 及更早版本。但是当我在 Swift 3 中更新它时,应用程序崩溃了。 这是swift 2.3中的代码 override func layoutAttributesFor
我想创建一个自定义 UICollectionViewFlowLayout 来更改标题和单元格在 Collection View 中的显示方式。我将 UICollectionViewFlowLayout
我正在实现自定义流布局。它有 2 个主要的重写方法来确定单元格的位置:layoutAttributesForElementsInRect 和 layoutAttributesForItemAtInde
我有一个包含项目的 UICollectionView。我希望中心的项目是全彩色的,而靠近收藏 View 垂直边界的项目会慢慢淡出。我想出了 layoutAttributesForElementsInR
我已经创建了自定义布局子类 UICollectionViewLayout。它完全按照我的需要工作,但是当集合只有少量元素(如“3”)时,layoutAttributesForElementsInRec
我想在 iPhone 应用程序中模仿 Sony Xperia 中提供的图库应用程序的功能。我的画廊应用程序,图像按日期分组显示在网格中,该部分的第一张照片是其他照片的两倍。放大/缩小时,所有照片都会缩
当我将我的项目从 Swift 1.2 迁移到 2.0 时,我遇到了一个问题:我正在为我的 UICollectionView 使用自定义布局,它在 Swift 1.2 中运行良好。但是,在 Swift
我是一名优秀的程序员,十分优秀!