【问题标题】:UICollectionView custom layout issue with layoutAttributesForElementsInRect:rectUICollectionView 自定义布局问题与 layoutAttributesForElementsInRect:rect
【发布时间】:2014-06-24 20:55:35
【问题描述】:

在我的使用中

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect

在自定义布局子类中,我只看到 rect 坐标值大多是 1024 的倍数。对吗?我做错了什么?

以下是我在 UICollectionView 上滚动时看到的值,其尺寸为宽度 = 3780、高度 = 3310,用于矩形(已删除重复项):

 rect {{0, 0}, {1024, 1024}}
 rect {{0, 0}, {2048, 1024}}
 rect {{0, 0}, {2048, 2048}}
 rect {{0, 1024}, {2048, 1024}}
 rect {{0, 1024}, {2048, 2048}}
 rect {{0, 2048}, {2048, 1024}}
 rect {{0, 2048}, {2048, 1262}}
 rect {{1024, 2048}, {2048, 1262}}
 rect {{2048, 2048}, {1732, 1262}}
 rect {{2048, 2048}, {1732, 1024}}
 rect {{2048, 1024}, {1732, 2048}}
 rect {{1024, 1024}, {2048, 2048}}
 rect {{1024, 1024}, {2048, 1024}}
 rect {{1024, 0}, {2048, 2048}}
 rect {{1024, 0}, {1024, 2048}}
 rect {{0, 0}, {2048, 2048}}
 rect {{0, 0}, {2048, 1024}}
 rect {{-1024, 0}, {2048, 1024}}
 rect {{-1024, 0}, {2048, 2048}}
 rect {{-0, 0}, {1024, 2048}}
 rect {{0, 0}, {2048, 2048}}
 rect {{1024, 0}, {2048, 2048}}
 rect {{2048, 0}, {1732, 2048}}

我希望看到的是原点反映 contentOffset,并且尺寸始终是屏幕的尺寸。

有什么想法吗?

两个细节:

我在 iPad 上进行测试,我在边界更改时使布局无效,这就是为什么当我滚动时会调用 layoutAttributesForElementsInRect 的原因。

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return YES;
}

【问题讨论】:

  • 我不能依赖这些奇怪的边界变化。我得到同样的东西。出于我的目的,我刚刚制作了一个位于原点.zero 和大小collectionView.contentSize 的矩形。这总是给我每一个项目,我可以检查可见的屏幕矩形。

标签: ios uicollectionview uicollectionviewlayout


【解决方案1】:

Apple 在 devforums 上对此的回答是遵守他们的文档并返回与 rect 参数相交的任何元素,而不考虑 rect 是否有意义。

【讨论】:

    猜你喜欢
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    相关资源
    最近更新 更多