UICollectionView 上的装饰视图在每次插入时都重复 [英] DecorationViews on UICollectionView are duplicated on every insert
问题描述
我正在尝试使用 UICollectionView 创建书架,与 iBooks 应用程序不同.
它工作得很好,但是每当我插入一个新项目到视图中(通过调用insertItemsAtIndexPaths:
),该项目被正确插入,但我的货架项目(是 DecorationViews,UICollectionReusableView
的子类越来越暗,显然被一遍又一遍地绘制.但是,如果在 UICollectionView
上调用 reloadData
,一切都会正确绘制.
这是我在派生的 UICollectionViewFlowLayout
类中所做的:
- (void)prepareLayout
计算框架装饰视图- (NSArray *)layoutAttributesForElementsInRect: 添加UICollectionViewLayoutAttributes
用于所有与正则- (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:(NSIndexPath *)
将我的项目属性的zIndex
调整为 1- (UICollectionViewLayoutAttributes*)layoutAttributesForDecorationViewOfKind:(NSString *) atIndexPath:(NSIndexPath *)
为我的书架调整zIndex
属性为 0
就是这样.我错过了什么吗?
听起来像(另一个)装饰视图的错误.我提交了一个错误,当设备旋转时它们会重复.>
I am trying to create a book shelf with an UICollectionView, not unlike the iBooks app.
It works nicely, however whenever I insert a new item into the view (by calling insertItemsAtIndexPaths:
), the item is inserted correctly, but my shelf items (which are DecorationViews, subclasses of UICollectionReusableView
) are getting darker and darker, obviously being painted over and over again.
However, if a call reloadData
on the UICollectionView
everything is painted correct.
This is what I did in my derived UICollectionViewFlowLayout
class:
- (void)prepareLayout
Calculating the frames for the DecorationViews- (NSArray *)layoutAttributesForElementsInRect: Adding UICollectionViewLayoutAttributes
for all shelves which intersect the rect- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)
AdjustingzIndex
for my item attributes to 1- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *) atIndexPath:(NSIndexPath *)
AdjustingzIndex
for my shelf attributes to 0
That's it. Did I miss something?
Sounds like (another) bug with decoration views. I've filed a bug that they're duplicated when the device is rotated.
这篇关于UICollectionView 上的装饰视图在每次插入时都重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!