DecorationViews on UICollectionView are duplicated on every insert

对着背影说爱祢 提交于 2019-12-24 01:08:36

问题


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 *) Adjusting zIndex for my item attributes to 1

  • - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *) atIndexPath:(NSIndexPath *) Adjusting zIndex for my shelf attributes to 0

That's it. Did I miss something?


回答1:


Sounds like (another) bug with decoration views. I've filed a bug that they're duplicated when the device is rotated.



来源:https://stackoverflow.com/questions/14882837/decorationviews-on-uicollectionview-are-duplicated-on-every-insert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!