UICollectionView Decoration and Supplementary views can not be moved

前端 未结 5 2036
耶瑟儿~
耶瑟儿~ 2021-02-01 07:40

In UICollectionView decoration and supplementary views seem to be a big mystery. There seems to be next to no example code at the moment. I managed to get both type

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 07:43

    I know this is an old question but I came across this when having problems with supplementary views being duplicated all over the place when invalidating a layout. I believe it's a bug, and I fixed it by ove-riding invalidateLayout in my layout object and removing the supplementary views as below:

    - (void)invalidateLayout {
        [super invalidateLayout];
        // Manually remove all suplementary views of a certain type
        /**
         ** This appears to be a BUG. Invalidate view does not remove suplementary view
         **     from the view hierachy. But they are Orphaned so stay on screen. 
         **/
        for (UIView *subview in [self.collectionView subviews]) {
            if ([subview isKindOfClass:[UICollectionReusableView class]]) {
                [subview removeFromSuperview];
            }
        }
    }
    

    Replace UICollectionReusableView with the class of your re-usable view that is being left on screen.

    Hope this helps someone.

提交回复
热议问题