UICollectionView shows scroll indicator for each section (zIndex header is broken)

When scrolling mine UICollectionView

, more than one scroll indicator is displayed. I noticed that there is one for each section of the collection. See screenshot displaying three at the same time:

enter image description here

Has anyone experienced the same problem? I am using Xcode 9 beta 3. My collection setup is pretty common:

private let formCollectionView: UICollectionView = {
        let collectionViewLayout = UICollectionViewFlowLayout()
        collectionViewLayout.minimumLineSpacing = 0
        collectionViewLayout.minimumInteritemSpacing = 0
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
        collectionView.translatesAutoresizingMaskIntoConstraints = false
        collectionView.backgroundColor = UIColor.clear
        return collectionView
}()

      

Edit 10/16/2017

Even Twitter has a problem like this:

enter image description here

+3


source to share


4 answers


you can fix this problem in the method.as delete in the following example

wasps

- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
    {
        if (@available(iOS 11.0, *)) {
            if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) {
                view.layer.zPosition = 0;
            }
        }
    }

      



fast

public func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath)
{
    if (elementKind == UICollectionElementKindSectionHeader) {
        view.layer.zPosition = 0;
    }
}

      

+6


source


So, first of all, there is radar .

There is a suggested solution. I was partially successful doing this shit inside my subclass UICollectionReusableView

.



override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
    super.apply(layoutAttributes)
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.01) {
        self.layer.zPosition = 0
    }
}

      

I say in part because if yours is slightly longer UICollectionView

it is still corrupted for some headers. Most of them are fine. So it depends on your situation. Hopefully the radar will be reviewed soon.

+2


source


These are not multiple scroll indicators. The z-index of the header views is higher than the scroll indicator.

Edit: Found something a little more interesting, if you run the view debugger, the scroll indicator is above the headers ... something weird is happening.

+1


source


There is an easy way to fix this problem. In the section header title class, you can override the method layoutSubviews

and write:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.layer.zPosition = 0;
}

      

Since before iOS11 the zPosition for the slice level defaults to 0, but in iOS11 this defaults to 1.

0


source







All Articles