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?