我正在尝试使用UICollectionView创建一个书架,与iBooks应用程序类似。它的工作很好,但是每当我通过调用insertItemsAtIndexPaths:将新项目插入视图时,该项目会被正确插入,但我的书架项(这些是DecorationViews,是UICollectionReusableView的子类)变得越来越暗,显然一遍又一遍地被涂上颜色。但是,如果在UICollectionView上调用reloadData,一切都会正确绘制。
这是我在派生的UICollectionViewFlowLayout类中所做的:
- (void)prepareLayout:计算DecorationViews的框架。 - (NSArray *)layoutAttributesForElementsInRect:为所有与矩形相交的书架添加UICollectionViewLayoutAttributes。 - (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:将我的项目属性的zIndex调整为1。 - (UICollectionViewLayoutAttributes*)layoutAttributesForDecorationViewOfKind:atIndexPath:将我的书架属性的zIndex调整为0。
就是这样。我有什么遗漏吗?
这是我在派生的UICollectionViewFlowLayout类中所做的:
- (void)prepareLayout:计算DecorationViews的框架。 - (NSArray *)layoutAttributesForElementsInRect:为所有与矩形相交的书架添加UICollectionViewLayoutAttributes。 - (UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:将我的项目属性的zIndex调整为1。 - (UICollectionViewLayoutAttributes*)layoutAttributesForDecorationViewOfKind:atIndexPath:将我的书架属性的zIndex调整为0。
就是这样。我有什么遗漏吗?