我正在尝试使用 UICollectionView 创建一个书架,与 iBooks 应用程序不同。
它工作得很好,但是每当我插入一个新项目到 View 中(通过调用insertItemsAtIndexPaths:
),该项目被正确插入,但是我的货架项目(都是DecorationViews,UICollectionReusableView
的子类)颜色越来越深,明显是刷了一遍又一遍。
但是,如果在 UICollectionView
上调用 reloadData
,一切都会正确绘制。
这是我在派生的 UICollectionViewFlowLayout
类中所做的:
- (void)prepareLayout
计算帧 装饰 View- (NSArray *)layoutAttributesForElementsInRect: 添加 UICollectionViewLayoutAttributes
适用于所有与 正确- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)
将我的项目属性的zIndex
调整为 1- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *) atIndexPath:(NSIndexPath *)
为我的书架调整zIndex
属性为 0
就是这样。 我错过了什么吗?
最佳答案
听起来像是装饰 View 的(另一个)错误。我已经提交了 bug当设备旋转时它们会复制。
关于ios - UICollectionView 上的 DecorationViews 在每次插入时都是重复的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882837/