请参阅附呈的图片。

我使用了一个相当基本的UIFlowLayout子类来陪伴视图,但是无论我尝试了什么,它都决定它不需要绘制单元格0,
但是,如果我向下滚动并向上滚动,它将正确地绘制它。
它似乎是一个iOS SDK错误,但需要进一步研究。只是想知道有没有人想试试这个。
发布于 2014-05-19 01:59:42
这个答案实际上有助于解决这个问题:
UICollectionView flowLayout not wrapping cells correctly (iOS)1
但是我的情况是唯一的,因为我使用一个UIDynamicAnimator来计算布局属性。
所以我的代码是这样写的:
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
return [self.dynamicAnimator itemsInRect:rect];
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
return [self.dynamicAnimator layoutAttributesForSupplementaryViewOfKind: kind atIndexPath:indexPath];
}对此:
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
NSMutableArray *newAttributes = [NSMutableArray arrayWithCapacity:attributes.count];
for (UICollectionViewLayoutAttributes *attribute in attributes) {
if ((attribute.frame.origin.x + attribute.frame.size.width <= self.collectionViewContentSize.width) &&
(attribute.frame.origin.y + attribute.frame.size.height <= self.collectionViewContentSize.height)) {
[newAttributes addObject:attribute];
}
}
return newAttributes;
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
return [self.dynamicAnimator layoutAttributesForSupplementaryViewOfKind: kind atIndexPath:indexPath];
}问题解决了!我的-(BOOL)shouldInvalidateLayoutForBoundsChange代码中的逻辑做错了一些事情,这是可有可无的,但我已经检查过了,逻辑看起来还不错。
https://stackoverflow.com/questions/23728619
复制相似问题