uicollectionview加载得很厉害 [英] uicollectionview Loads wierdly
本文介绍了uicollectionview加载得很厉害的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用自定义集合cell.set创建了一个集合视图,其中flowlayout为
I created a collection view with custom collection cell.set with flowlayout as
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(250, 480)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[self.templateCollectionView setCollectionViewLayout:flowLayout];
我将其设置为水平,但仍然在图中放错了单元格,请参阅 att mmp
放错位置&如果我们滚动并加载它,它将返回到正确的位置。任何人都可以提出这方面的错误吗?
I set it horizontal but still a cell is misplaced in figure see att mmp
misplaced & it will back in its correct position if we scroll and load it back. Can anyone suggest whats wrong in this ?
推荐答案
有一个解决方法这个答案对我有用。下面是我用于水平滚动编辑的修复程序。基本上只是过滤掉下面提供坏帧的属性项。
There is a work around on this answer that works for me. Below is the fix I used edited for horizontal scrolling. Basically just filtering out the attributes item that is providing the bad frame down below.
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
NSMutableArray *newAttributes = [NSMutableArray arrayWithCapacity:attributes.count];
for (UICollectionViewLayoutAttributes *attribute in attributes) {
if (attribute.frame.origin.y + attribute.frame.size.height <= self.collectionViewContentSize.height) {
[newAttributes addObject:attribute];
}
}
return newAttributes;
}
这篇关于uicollectionview加载得很厉害的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文