IOS11 scroll indicator UICollectionSectionHeader

I created one view project and added collectionView. I registered a simple subclass of UICollectionReusableView

final class TestReusableView: UICollectionReusableView { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor.red } ... } 

Set up a data source and delegate yourself

 extension ViewController: UICollectionViewDataSource { func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 100 } func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kHeader, for: indexPath) return headerView } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) cell.backgroundColor = UIColor.blue return cell } } extension ViewController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { return CGSize(width: collectionView.bounds.width, height: 88) } } 

As a result, the section title appears to be located above the vertical scroll bar. However, if I run the application against the 10.3.1 simulator, the behavior works as I expected.

The red section header is on top of the scroll indicator.

+5
source share
3 answers

this works for me:

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

}

+4
source

I could not try, but you can try adding this to your viewDidLoad() :

 let flow = collectionView.collectionViewLayout as! UICollectionViewFlowLayout flow.sectionHeadersPinToVisibleBounds = true 
+1
source

Well, even I encountered the same problem in my application, and it was released for release after 2 weeks. I did not have time to research why this only happens in iOS 11. Therefore, the quick work around which I did this, replacing the use of headerView with footerView, since footerView does not have this problem.

0
source

Source: https://habr.com/ru/post/1272628/


All Articles