在我使用
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
在自定义布局子类中,我只能看到通常是1024的倍数的rect坐标值。对吗?我究竟做错了什么?
这是我在UICollectionView上滚动时看到的值,其中rect的宽度为width = 3780,height = 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;
}
最佳答案
Apple在devforums上对此的回答是坚持其文档并返回与rect参数相交的任何元素,而不考虑rect是否有意义。
关于ios - UICollectionView自定义布局问题,带有layoutAttributesForElementsInRect:rect,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24396095/