Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView showing scroll indicator for every section (header zIndex broken)

When scrolling through my UICollectionView it's showing more than one scroll indicator. I've noticed there is a one for every section in the collection. See screenshot displaying three at the same time:

enter image description here

Anyone experienced same issue? I am using Xcode 9 beta 3. My collectionview setup is quite 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 seems having this issue:

enter image description here

like image 794
Viktor Kucera Avatar asked Jul 20 '17 13:07

Viktor Kucera


2 Answers

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

Objective-C

- (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;
            }
        }
    }

Swift

func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) {
    if elementKind == UICollectionView.elementKindSectionHeader {
        view.layer.zPosition = 0
    }
}
like image 90
zhiyong.Zou Avatar answered Jan 04 '23 13:01

zhiyong.Zou


Ok, so first of all there is a radar already.

There is a proposed workaround. I was partially successful with doing this crap inside my UICollectionReusableView subclass.

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

I am saying partially because if you have a little bit longer UICollectionView it's still corrupted for some headers. Most of them are ok though. So it depends on your situation. Hopefully that radar will be addressed soon.

like image 27
Viktor Kucera Avatar answered Jan 04 '23 11:01

Viktor Kucera