6

I try to find a workaround for this radar: http://www.openradar.me/34308893

Currently in my - (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes I'm doing the following:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC * 50), dispatch_get_main_queue(), ^{
    self.layer.zPosition = 0;
});

But no matter how many NSEC_PER_MSEC I enter it doesn't work quite right, the scrolling indicator sometimes hides behind the headers, especially when ne headers appear. Is there another/better approach?

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • Maybe this solution will help: https://stackoverflow.com/questions/46518725/mapkit-mkmapview-zposition-does-not-work-anymore-on-ios11 – Serge Oct 24 '17 at 14:49

1 Answers1

9

I had a similar problem where a header view in a UICollectionView was getting rendered above another view that had it's zIndex set > 0 in a custom UICollectionViewFlowLayout.

The answer for me was to set the header view layer's zPosition in willDisplaySupplementaryView:

override public func collectionView(_ collectionView: UICollectionView,
                                    willDisplaySupplementaryView view: UICollectionReusableView,
                                    forElementKind elementKind: String,
                                    at indexPath: IndexPath) {
    if elementKind == UICollectionView.elementKindSectionHeader && type(of: view) == CollectionViewSectionHeaderView.self {
      view.layer.zPosition = -1
    }
  }

iOS11 doesn't seem to honor z-indexes in UICollectionViewFlowLayout subclasses.

conmulligan
  • 7,038
  • 6
  • 33
  • 44